struct Crystalizer::ByteFormat

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.cr
byte_format/deserializer.cr
byte_format/serializer.cr

Constructors

Class Method Summary

Instance Method Summary

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

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

[View source]

Class Method Detail

def self.deserialize(bytes : Bytes, to type : T.class) : T forall T #

[View source]
def self.deserialize(io : IO, to type : T.class) : T forall T #

[View source]
def self.serialize(io : IO, object) : Nil #

[View source]
def self.serialize(object) : Bytes #

[View source]
def self.string_delimiter : Char | Nil #

Byte to delimit the end of a String.


[View source]
def self.string_delimiter=(string_delimiter : Char | Nil) #

Byte to delimit the end of a String.


[View source]

Instance Method Detail

def 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.


[View source]
def 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.


[View source]
def deserialize(to type : Crystalizer::Type.class) #

[View source]
def deserialize(to type : Array.class | Deque.class | Set.class) #

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


[View source]
def deserialize(to type : Bool.class) #

[View source]
def deserialize(to type : Bytes.class) #

[View source]
def deserialize(to type : Enum.class) #

[View source]
def deserialize(to type : Hash.class) #

[View source]
def deserialize(to type : NamedTuple.class) #

[View source]
def deserialize(to type : Number::Primitive.class) #

[View source]
def deserialize(to type : Path.class) #

[View source]
def deserialize(to type : String.class) #

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


[View source]
def deserialize(to type : Tuple.class) #

[View source]
def deserialize(to type : T.class) : T forall T #

[View source]
def format : IO::ByteFormat #

[View source]
def format=(format : IO::ByteFormat) #

[View source]
def io : IO #

[View source]
def serialize(string : String, bytesize : Int) #

[View source]
def serialize(string : String, bytesize : Range(Int32 | Nil, Int32 | Nil)) #

[View source]
def serialize(object : Crystalizer::Type) #

[View source]
def serialize(number : Number::Primitive) #

[View source]
def serialize(bool : Bool) #

[View source]
def serialize(bytes : Bytes) #

[View source]
def serialize(object : Enum) #

[View source]
def serialize(object : NamedTuple | Hash) #

[View source]
def serialize(array : Array | Deque | Set | Tuple) #

[View source]
def serialize(string : Path | String | Symbol, add_delimiter : Bool = true) #

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


[View source]
def serialize(object : O) forall O #

[View source]
def string_delimiter : Char? #

[View source]
def string_delimiter=(string_delimiter : Char | Nil) #

[View source]