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.

Defined in:

byte_format.cr
byte_format/deserialize.cr
byte_format/serialize.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(io : IO = IO::Memory.new, format : IO::ByteFormat = IO::ByteFormat::SystemEndian, byte_delimiter : UInt8? = @@byte_delimiter) #

[View source]

Class Method Detail

def self.byte_delimiter : UInt8? #

Byte to delimit the end of a String.


[View source]
def self.byte_delimiter=(byte_delimiter : UInt8?) #

Byte to delimit the end of a String.


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

Instance Method Detail

def deserialize(to type : Tuple.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 .byte_delimiter.


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

[View source]
def io : IO #

[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) #

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


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

[View source]