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)

39.1. Structures

Archive

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

Fields
  • version : uint - Version of the archive format.

  • reading : bool - True if the archive is for reading, false for writing.

  • stream : Serializer ? - Serialization stream.

39.2. Classes

Serializer

Base class for serializers.

MemSerializer : Serializer

This serializer stores data in memory (in the array<uint8>) internal data buffer current reading offset last error code

MemSerializer.write(bytes: void? implicit; size: int) : bool()

Appends bytes at the end of the data.

Arguments
  • bytes : void? implicit

  • size : int

MemSerializer.read(bytes: void? implicit; size: int) : bool()

Reads bytes from data, advances the reading position.

Arguments
  • bytes : void? implicit

  • size : int

MemSerializer.error(code: string)

Sets the last error code.

Arguments
  • code : string

MemSerializer.OK() : bool()

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

MemSerializer.extractData() : array<uint8>()

Extract the data from the serializer.

MemSerializer.getCopyOfData() : array<uint8>()

Returns copy of the data from the seiralizer.

MemSerializer.getLastError() : string()

Returns last serialization error.

MemSerializer() : MemSerializer()

Initialize the serializer for reading or writing.

MemSerializer(from: array<uint8>) : MemSerializer()

Initialize the serializer for reading from the given data.

Arguments
  • from : array<uint8>

39.3. Serialization

serialize(arch: Archive; value: float3x3)

Serializes float3x3 matrix

Arguments
serialize(arch: Archive; value: float3x4)

Serializes float3x4 matrix

Arguments
serialize(arch: Archive; value: float4x4)

Serializes float4x4 matrix

Arguments
serialize(arch: Archive; value: string&)

Serializes string by serializing its length and characters.

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

Serialize raw data (straight up bytes for raw pod)

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

Read raw data (straight up bytes for raw pod)

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

Write raw data (straight up bytes for raw pod)

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

Serializes variant by serializing the index and the active field.

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

Serializes variant by serializing the index and the active field.

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

Serializes variant by serializing the index and the active field.

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

Serializes variant by serializing the index and the active field.

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

Serializes variant by serializing the index and the active field.

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

Serializes array by serializing its length and each element.

Arguments
  • arch : Archive

  • value : auto(TT)[-1]

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

Serializes array by serializing its length and each element.

Arguments
  • arch : Archive

  • value : array<auto(TT)>

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

Serializes table by serializing its length and each key-value pair.

Arguments
  • arch : Archive

  • value : table<auto(KT);auto(VT)>

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

Serializes nullable type by serializing a flag and the value if present.

Arguments

39.4. Memory archive

mem_archive_save(t: auto&) : auto()

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

Arguments
  • t : auto&

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

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

Arguments
  • data : array<uint8>

  • t : auto&

  • canfail : bool