struct Crystalizer::ByteFormat
- Crystalizer::ByteFormat
- Struct
- Value
- Object
Overview
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.
Defined in:
byte_format.crbyte_format/deserialize.cr
byte_format/serialize.cr
Constructors
Class Method Summary
-
.byte_delimiter : UInt8 | Nil
Byte to delimit the end of a
String
. -
.byte_delimiter=(byte_delimiter : UInt8 | Nil)
Byte to delimit the end of a
String
. - .deserialize(bytes : Bytes, to type : T.class) : T forall T
- .deserialize(io : IO, to type : T.class) : T forall T
- .serialize(io : IO, object) : Nil
- .serialize(object) : Bytes
Instance Method Summary
-
#deserialize(to type : Array.class | Deque.class | Set.class)
Requires the
@io
to be anIO::Memory
. - #deserialize(to type : Bool.class)
- #deserialize(to type : Bytes.class)
- #deserialize(to type : Enum.class)
- #deserialize(to type : Hash.class)
- #deserialize(to type : NamedTuple.class)
- #deserialize(to type : Number::Primitive.class)
- #deserialize(to type : Path.class)
-
#deserialize(to type : String.class)
Deserializes a
String
from reading from the#io
, delimited by a trailing.byte_delimiter
. - #deserialize(to type : Tuple.class)
- #deserialize(to type : T.class) : T forall T
- #io : IO
- #serialize(number : Number::Primitive)
- #serialize(bool : Bool)
- #serialize(bytes : Bytes)
- #serialize(object : Enum)
- #serialize(object : NamedTuple | Hash)
- #serialize(array : Array | Deque | Set | Tuple)
-
#serialize(string : Path | String | Symbol)
Serializes a
String
to bytes, written to the#io
, and add a trailing.byte_delimiter
. - #serialize(object : O) forall O
Constructor Detail
Class Method Detail
Instance Method Detail
Requires the @io
to be an IO::Memory
.
Deserializes a String
from reading from the #io
, delimited by a trailing .byte_delimiter
.
Serializes a String
to bytes, written to the #io
, and add a trailing .byte_delimiter
.