Repository navigation
io_serializable v0.3.0
Overview
This release adds support for named tuple serialization, including nested named tuples, nilable named tuples, and named tuples containing serializable objects.
New Features
Named Tuple Serialization
- Added support for all named tuple variants:
- Simple named tuples of primitive types
- Nested named tuples (named tuples containing other named tuples)
- Named tuples with nilable elements
- Nilable nested named tuples
- Named tuples containing enum values
- Named tuples containing serializable class instances
- Complex nested structures with named tuples containing serializable objects
Improved Float Serialization
- Comprehensive handling of special float values:
- Infinity and negative infinity
- NaN (Not a Number)
- Minimum and maximum representable values
- Very small values (near subnormal range)
- Very large values
- Subnormal numbers
- Negative zero (preserving sign bit)
- Common mathematical constants (π, e, etc.)
Improved Test Coverage
- Added extensive test suite for all implemented types
- Tests for all edge cases and special values
Improved Documentation
- Added comprehensive examples for named tuple serialization in README
- Added example code for serializing named tuples with class instances
- Enhanced code documentation
Usage Examples
# Basic named tuple serialization
named_tuple = {id: 42, name: "hello", value: 3.14, active: true}
io = IO::Memory.new
named_tuple.to_io(io)
io.rewind
restored_named_tuple = NamedTuple(id: Int32, name: String, value: Float64, active: Bool).from_io(io)# Named tuples with serializable classes
class Point
include IO::Serializable
property x : Int32
property y : Int32
def initialize(@x = 0, @y = 0)
end
end
point_named_tuple = {home: Point.new(x: 10, y: 20), work: Point.new(x: 30, y: 40)}
io = IO::Memory.new
point_named_tuple.to_io(io)
io.rewind
restored_points = NamedTuple(home: Point, work: Point).from_io(io)# Basic float serialization
class Point
include IO::Serializable
property x : Float64
property y : Float64
property z : Float32
def initialize(@x = 0.0, @y = 0.0, @z = 0.0_f32)
end
end
# Create and serialize a point
point = Point.new(x: 10.5, y: 20.75, z: 5.25_f32)
io = IO::Memory.new
point.to_io(io)
# Deserialize the point
io.rewind
restored_point = Point.from_io(io)# Handling special float values
class MathValues
include IO::Serializable
property pi : Float64 = Math::PI
property e : Float64 = Math::E
property infinity : Float64 = Float64::INFINITY
property nan : Float64 = Float64::NAN
def initialize
end
end
math = MathValues.new
io = IO::Memory.new
math.to_io(io)
io.rewind
restored_math = MathValues.from_io(io)