struct

Crystalizer::ByteFormat

Inherits Crystalizer::Serializer / Crystalizer::Deserializer / Struct / Value / Object

Byte format, as implemented in the stdlib: https://crystal-lang.org/api/master/IO/ByteFormat.html.

Important note: bytes representation of dynamic data structures like Array and Hash have no end delimiter. On an object, only one of it can be present as the last instance variable, otherwise they will collide with the next ones - having no delimiter to separate them.

Unions are also not supported.

Constructors

new(io : IO = IO::Memory.new, format : IO::ByteFormat = IO::ByteFormat::SystemEndian, string_delimiter : Char | Nil = @@string_delimiter)
Source

Class methods

deserialize(bytes : Bytes, to type : T.class) : T forall T
Source
deserialize(io : IO, to type : T.class) : T forall T
Source
serialize(io : IO, object) : Nil
Source
serialize(object) : Bytes
Source
string_delimiter

Byte to delimit the end of a String.

Source
string_delimiter=(string_delimiter : Char | Nil)

Byte to delimit the end of a String.

Source

Instance methods

deserialize(to type : String.class, bytesize : Range(Int32 | Nil, Int32 | Nil))

Deserializes a String from reading from the io, delimited by a trailing string_delimiter.

Source
deserialize(to type : String.class, bytesize : Int)

Deserializes a String from reading from the io. String is exactly bytesize bytes with no trailing @string_delimiter.

Source
deserialize(to type : Crystalizer::Type.class)
Source
deserialize(to type : Array.class | Deque.class | Set.class)

Requires the @io to be an IO::Memory.

Source
deserialize(to type : Bool.class)
Source
deserialize(to type : Bytes.class)
Source
deserialize(to type : Enum.class)
Source
deserialize(to type : Hash.class)
Source
deserialize(to type : NamedTuple.class)
Source
deserialize(to type : Number::Primitive.class)
Source
deserialize(to type : Path.class)
Source
deserialize(to type : String.class)

Deserializes a String from reading from the io, delimited by a trailing string_delimiter.

Source
deserialize(to type : Tuple.class)
Source
deserialize(to type : T.class) : T forall T
Source
format
Source
format=(format : IO::ByteFormat)
Source
serialize(string : String, bytesize : Int)
Source
serialize(string : String, bytesize : Range(Int32 | Nil, Int32 | Nil))
Source
serialize(object : Crystalizer::Type)
Source
serialize(number : Number::Primitive)
Source
serialize(bool : Bool)
Source
serialize(bytes : Bytes)
Source
serialize(object : Enum)
Source
serialize(object : NamedTuple | Hash)
Source
serialize(array : Array | Deque | Set | Tuple)
Source
serialize(string : Path | String | Symbol, add_delimiter : Bool = true)

Serializes a String to bytes, written to the io, and add a trailing string_delimiter.

Source
serialize(object : O) forall O
Source
string_delimiter
Source
string_delimiter=(string_delimiter : Char | Nil)
Source

Nested types