39. General prupose serialization

The archive module implements general purpose serialization infrastructure.

All functions and symbols are in “archive” module, use require to get access to it.

require daslib/archive

To correctly support serialization of the specific type, you need to define and implement serialize method for it. For example this is how DECS implements component serialization:

def public serialize ( var arch:Archive; var src:Component )
    arch |> serialize(src.name)
    arch |> serialize(src.hash)
    arch |> serialize(src.stride)
    arch |> serialize(src.info)
    invoke(src.info.serializer, arch, src.data)
Archive

Archive fields are

version

uint

reading

bool

stream

archive::Serializer ?

Archive is a combination of serialization stream, and state (version, and reading status).

39.1. Classes

Serializer

Base class for serializers.

it defines as follows

Serializer.write(self: Serializer; bytes: void? const implicit; size: int const)

write returns bool

argument

argument type

self

archive::Serializer

bytes

void? const implicit

size

int const

Write binary data to stream.

Serializer.read(self: Serializer; bytes: void? const implicit; size: int const)

read returns bool

argument

argument type

self

archive::Serializer

bytes

void? const implicit

size

int const

Read binary data from stream.

Serializer.error(self: Serializer; code: string const)

argument

argument type

self

archive::Serializer

code

string const

Report error to the archive

Serializer.OK(self: Serializer)

OK returns bool

Return status of the archive

MemSerializer : Serializer

This serializer stores data in memory (in the array<uint8>)

it defines as follows

data : array<uint8>
readOffset : int
lastError : string
MemSerializer.write(self: Serializer; bytes: void? const implicit; size: int const)

write returns bool

argument

argument type

self

archive::Serializer

bytes

void? const implicit

size

int const

Appends bytes at the end of the data.

MemSerializer.read(self: Serializer; bytes: void? const implicit; size: int const)

read returns bool

argument

argument type

self

archive::Serializer

bytes

void? const implicit

size

int const

Reads bytes from data, advances the reading position.

MemSerializer.error(self: Serializer; code: string const)

argument

argument type

self

archive::Serializer

code

string const

Sets the last error code.

MemSerializer.OK(self: Serializer)

OK returns bool

Implements ‘OK’ method, which returns true if the serializer is in a valid state.

MemSerializer.extractData(self: MemSerializer)

extractData returns array<uint8>

Extract the data from the serializer.

MemSerializer.getCopyOfData(self: MemSerializer)

getCopyOfData returns array<uint8>

Returns copy of the data from the seiralizer.

MemSerializer.getLastError(self: MemSerializer)

getLastError returns string

Returns last serialization error.

39.2. Serialization

serialize(arch: Archive; value: float3x3)

argument

argument type

arch

archive::Archive

value

math::float3x3

todo: implement preallocat string with raii

serialize(arch: Archive; value: float3x4)

argument

argument type

arch

archive::Archive

value

math::float3x4

todo: implement preallocat string with raii

serialize(arch: Archive; value: float4x4)

argument

argument type

arch

archive::Archive

value

math::float4x4

todo: implement preallocat string with raii

serialize(arch: Archive; value: string&)

argument

argument type

arch

archive::Archive

value

string&

todo: implement preallocat string with raii

serialize_raw(arch: Archive; value: auto(TT)&)

serialize_raw returns auto

argument

argument type

arch

archive::Archive

value

auto(TT)&

Serialize raw data (straight up bytes for raw pod)

read_raw(arch: Archive; value: auto(TT)&)

read_raw returns auto

argument

argument type

arch

archive::Archive

value

auto(TT)&

Read raw data (straight up bytes for raw pod)

write_raw(arch: Archive; value: auto(TT)&)

write_raw returns auto

argument

argument type

arch

archive::Archive

value

auto(TT)&

Write raw data (straight up bytes for raw pod)

serialize(arch: Archive; value: auto(TT)&)

serialize returns auto

argument

argument type

arch

archive::Archive

value

auto(TT)&

todo: implement preallocat string with raii

serialize(arch: Archive; value: auto(TT)&)

serialize returns auto

argument

argument type

arch

archive::Archive

value

auto(TT)&

todo: implement preallocat string with raii

serialize(arch: Archive; value: auto(TT)&)

serialize returns auto

argument

argument type

arch

archive::Archive

value

auto(TT)&

todo: implement preallocat string with raii

serialize(arch: Archive; value: auto(TT)&)

serialize returns auto

argument

argument type

arch

archive::Archive

value

auto(TT)&

todo: implement preallocat string with raii

serialize(arch: Archive; value: auto(TT)&)

serialize returns auto

argument

argument type

arch

archive::Archive

value

auto(TT)&

todo: implement preallocat string with raii

serialize(arch: Archive; value: auto(TT)[])

serialize returns auto

argument

argument type

arch

archive::Archive

value

auto(TT)[-1]

todo: implement preallocat string with raii

serialize(arch: Archive; value: array<auto(TT)>)

serialize returns auto

argument

argument type

arch

archive::Archive

value

array<auto(TT)>

todo: implement preallocat string with raii

serialize(arch: Archive; value: table<auto(KT);auto(VT)>)

serialize returns auto

argument

argument type

arch

archive::Archive

value

table<auto(KT);auto(VT)>

todo: implement preallocat string with raii

serialize(arch: Archive; value: auto(TT)?)

serialize returns auto

argument

argument type

arch

archive::Archive

value

auto(TT)?

todo: implement preallocat string with raii

39.3. Memory archive

mem_archive_save(t: auto&)

mem_archive_save returns auto

argument

argument type

t

auto&

Saves the object to a memory archive. Result is array<uint8> with the serialized data.

mem_archive_load(data: array<uint8>; t: auto&; canfail: bool const)

mem_archive_load returns bool

argument

argument type

data

array<uint8>

t

auto&

canfail

bool const

Loads the object from a memory archive. data is the array<uint8> with the serialized data, returned from mem_archive_save.