crow/serialize.crow
(source)
Functions for converting values to/from byte arrays.
For JSON serialization, see the crow/json
module.
serialize
[t
] spec
A type is serializable if it can convert to and from a byte array.
Implementations should ensure that a.to-bytes.from-bytes == a
.
to-bytes
nat8
array
(a
nat8
array
)
Identity function to ensure that byte lists are trivially serializable.
from-bytes
nat8
array
(a
nat8
array
)
from-bytes
string
(a
nat8
array
)
to-bytes
nat8
array
(a
nat64
)
Convert a number to a nat8[] simply by taking its component bytes in big-endian order.
This strips leading 0 bytes.
to-8-bytes
nat8
array
(a
nat64
)
Unlike a to-bytes
, this always returns an 8-byte array, including any leading 0 bytes.
from-bytes
nat64
(a
nat8
array
)
This works for the result of either to-bytes
or to-8-bytes
.