NAME
std/data/cbor - CBOR encoding and decoding for ZuzuScript.
SYNOPSIS
from std/data/cbor import CBOR, TaggedValue;
let codec := new CBOR();
let bytes := codec.encode({ answer: 42 });
let value := codec.decode(bytes);
// Decode CBOR maps to Zuzu PairLists instead of Dicts.
// This preserves key order and allows duplicate keys.
codec := new CBOR( pairlists: true );
IMPLEMENTATION SUPPORT
This module is supported by zuzu.pl, zuzu-rust, and zuzu-js on Node and Electron. It is partially supported by zuzu-js in the browser: in-memory CBOR encode/decode coverage passes, but file-backed load/dump coverage is unsupported because browser filesystem capability is unavailable.
DESCRIPTION
Pure-Zuzu implementation of CBOR (RFC 8949).
EXPORTS
Classes
TaggedValue({ tag: Number, value: value })Constructs a tagged CBOR value. Returns:
TaggedValue. Stores the CBOR tag number and associated value.CBOR({ pairlists?: Boolean })Constructs a CBOR codec. Returns:
CBOR. Thepairlistsoption makes decoded maps return asPairListvalues instead ofDictvalues.codec.encode(value)Parameters:
valueis any CBOR-encodable ZuzuScript value. Returns:BinaryString. Encodesvalueas CBOR bytes.codec.encode_binarystring(value)Alias for
codec.encode(value).codec.decode(BinaryString raw)Parameters:
rawis CBOR data. Returns: value. Decodes CBOR bytes into the equivalent ZuzuScript value.codec.decode_binarystring(BinaryString raw)Alias for
codec.decode(raw).codec.load(Path path)Parameters:
pathis astd/ioPath. Returns: value. Reads CBOR bytes frompathand decodes them.codec.dump(Path path, value)Parameters:
pathis astd/ioPathandvalueis any CBOR-encodable value. Returns:null. Encodesvalueand writes CBOR bytes topath.
COPYRIGHT AND LICENCE
std/data/cbor is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.