Marshal

GitHub   Edit on GitHub

Utilities for serializing and deserializing Grain data.

Added in 0.5.3 No other changes yet.
1
from "marshal" include Marshal
1
Marshal.marshal(1)
1
Marshal.marshal("Hello World")
1
Marshal.unmarshal(b"\x03\x00\x00\x00")

Values

Functions and constants included in the Marshal module.

Marshal.marshal

Added in 0.5.3 No other changes yet.
1
marshal : (value: a) => Bytes

Serialize a value into a byte-based representation suitable for transmission across a network or disk storage. The byte-based representation can be deserialized at a later time to restore the value.

Parameters:

param type description
value a The value to serialize

Returns:

type description
Bytes A byte-based representation of the value

Examples:

1
Marshal.marshal(1) == b"\x03\x00\x00\x00"
1
Marshal.marshal("🌾") == Marshal.marshal("🌾")

Marshal.unmarshal

Added in 0.5.3 No other changes yet.
1
unmarshal : (bytes: Bytes) => Result<a, String>

Deserialize the byte-based representation of a value back into an in-memory value. This operation is not type-safe, and it is recommended that a type annotation is used to declare the type of the unmarshaled value. While attempts to unmarshal bad data will fail, this operation is still generally unsafe and great care should be taken to ensure that the data being unmarshaled corresponds to the expected type.

Parameters:

param type description
bytes Bytes The data to deserialize

Returns:

type description
Result<a, String> An in-memory value

Examples:

1
Marshal.unmarshal(Marshal.marshal('🌾')) == Ok('🌾')
1
Marshal.unmarshal(b"\x03\x00\x00\x00") == Ok(1)
This is a notification!