Description

CborHandle is a Handle for the CBOR encoding format, defined at http://tools.ietf.org/html/rfc7049 and documented further at http://cbor.io .

CBOR is comprehensively supported, including support for:

- indefinite-length arrays/maps/bytes/strings
- (extension) tags in range 0..0xffff (0 .. 65535)
- half, single and double-precision floats
- all numbers (1, 2, 4 and 8-byte signed and unsigned integers)
- nil, true, false, ...
- arrays and maps, bytes and text strings

None of the optional extensions (with tags) defined in the spec are supported out-of-the-box. Users can implement them as needed (using SetExt), including spec-documented ones:

- timestamp, BigNum, BigFloat, Decimals, Encoded Text (e.g. URL, regexp, base64, MIME Message), etc.

To encode with indefinite lengths (streaming), users will use (Must)Encode methods of *Encoder, along with writing CborStreamXXX constants.

For example, to encode "one-byte" as an indefinite length string:

var buf bytes.Buffer
e := NewEncoder(&buf, new(CborHandle))
buf.WriteByte(CborStreamString)
e.MustEncode("one-")
e.MustEncode("byte")
buf.WriteByte(CborStreamBreak)
encodedBytes := buf.Bytes()
var vv interface{}
NewDecoderBytes(buf.Bytes(), new(CborHandle)).MustDecode(&vv)
// Now, vv contains the same string "one-byte"

CborHandle is referenced in 0 repositories