title |
---|
Marshal |
Utilities for serializing and deserializing Grain data.
Added in 0.5.3
No other changes yet.
include "marshal"
Marshal.marshal(1)
Marshal.marshal("Hello World")
Marshal.unmarshal(b"\x03\x00\x00\x00")
Functions and constants included in the Marshal module.
Added in 0.5.3
No other changes yet.
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:
Marshal.marshal(1) == b"\x03\x00\x00\x00"
Marshal.marshal("馃尵") == Marshal.marshal('馃尵')
Added in 0.5.3
No other changes yet.
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:
Marshal.unmarshal(Marshal.marshal('馃尵')) == Ok('馃尵')
Marshal.unmarshal(b"\x03\x00\x00\x00") == Ok(1)