ESC
No recent searches
Search by
Standard Library  /  Marshal

Marshal

Utilities for serializing and deserializing Grain data.

Edit on GitHub
Added in 0.5.3 No other changes yet.
from "marshal" include Marshal
Marshal.marshal(1)
Marshal.marshal("Hello World")
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.
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:

value: The value to serialize

Returns:

Bytes: A byte-based representation of the value

Examples:

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

Marshal.unmarshal

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:

bytes: The data to deserialize

Returns:

Result<a, String>: An in-memory value

Examples:

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

Sign up for farm-to-inbox developer news

You can unsubscribe at any time. Read our privacy policy.

Copyright © 2024 The Grain Programming Language