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.
Included Modules
Extended Modules
Defined in:
byte_format.crbyte_format/deserializer.cr
byte_format/serializer.cr
Constructors
Class Method Summary
- .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
-
.string_delimiter : Char | Nil
Byte to delimit the end of a
String
. -
.string_delimiter=(string_delimiter : Char | Nil)
Byte to delimit the end of a
String
.
Instance Method Summary
-
#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
. -
#deserialize(to type : String.class, bytesize : Int)
Deserializes a
String
from reading from the#io
. - #deserialize(to type : Crystalizer::Type.class)
-
#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#string_delimiter
. - #deserialize(to type : Tuple.class)
- #deserialize(to type : T.class) : T forall T
- #format : IO::ByteFormat
- #format=(format : IO::ByteFormat)
- #io : IO
- #serialize(string : String, bytesize : Int)
- #serialize(string : String, bytesize : Range(Int32 | Nil, Int32 | Nil))
- #serialize(object : Crystalizer::Type)
- #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, add_delimiter : Bool = true)
Serializes a
String
to bytes, written to the#io
, and add a trailing#string_delimiter
. - #serialize(object : O) forall O
- #string_delimiter : Char?
- #string_delimiter=(string_delimiter : Char | Nil)
Instance methods inherited from module Crystalizer::Serializer
serialize(object : O) forall O
serialize
Instance methods inherited from module Crystalizer::Deserializer
deserialize(to type : T.class) forall T
deserialize
Constructor Detail
Class Method Detail
Instance Method Detail
Deserializes a String
from reading from the #io
, delimited by a trailing #string_delimiter
.
Deserializes a String
from reading from the #io
. String is exactly bytesize
bytes with no trailing @string_delimiter
.
Requires the @io
to be an IO::Memory
.
Deserializes a String
from reading from the #io
, delimited by a trailing #string_delimiter
.
Serializes a String
to bytes, written to the #io
, and add a trailing #string_delimiter
.