object_to_u8array


object_to_u8array(obj, @optional encoder = identity)
      

Return a byte array that encodes the object obj.

The optional encoder parameter is a function that take a single argument. As the serializer walks through obj, it calls encoder on each sub-object that is encountered. The encoder is used to perform custom transformations on the sub-objects and thereby support custom encodings.

Some objects like tasks and streams are non-serializable. An encoder may be defined to serialize even such objects.

Examples:


let e = object_to_u8array([1, "hi", 3])
u8array_to_object(e)
// [1, hi, 3]

function f(x) x * 100
e = object_to_u8array(f)
u8array_to_object(e)(10)
// 1000
      

Also see:

byte_array_writer


Core Module Index | Contents