std.cbor
rfc 8949; writer emits preferred (shortest) forms, reader allocates nothing
CborError
Section titled “CborError”pub CborError :: errors { truncated, malformed, bad_text, too_deep,}truncated: the bytes end in the middle of an itemmalformed: invalid header, or a straybreakbad_text: a text string that is not UTF-8too_deep:skiphit 1000 nesting levels
pub Kind :: enum { uint, negint, bytes, text, array, map, tag, simple, boolean, null_value, undefined, float, end,}uint:valuenegint: -1 -valuebytes:datatext:data, UTF-8array:valueitems followmap:valuepairs follow, each a key and its valuetag: the tagvalue; the item it tags followssimple: unassigned simple value, number invalueboolean:value1 for true, 0 for falsefloat:numberend:breakclosing anindefiniteitem
pub Item :: struct { kind: Kind, value: u64, data: []const u8, number: f64, indefinite: bool,}from Reader.next; data slices the input
Item.as_i64
Section titled “Item.as_i64”pub as_i64 :: fn(self: *Self) -> ?i64uint/negint as i64; null if it doesn’t fit
pub Out :: struct { w: *Writer, failed: bool,}caller keeps item counts right; end closes indefinites; write errors show in finish
Out.uint
Section titled “Out.uint”pub uint :: fn(self: *Self, v: u64)Out.int
Section titled “Out.int”pub int :: fn(self: *Self, v: i64)Out.bytes
Section titled “Out.bytes”pub bytes :: fn(self: *Self, b: []const u8)Out.text
Section titled “Out.text”pub text :: fn(self: *Self, s: []const u8)utf-8 not checked
Out.begin_array
Section titled “Out.begin_array”pub begin_array :: fn(self: *Self, n: usize)write n items next
Out.begin_map
Section titled “Out.begin_map”pub begin_map :: fn(self: *Self, n: usize)write n key/value pairs next
Out.begin_array_indefinite
Section titled “Out.begin_array_indefinite”pub begin_array_indefinite :: fn(self: *Self)write the items, then end
Out.begin_map_indefinite
Section titled “Out.begin_map_indefinite”pub begin_map_indefinite :: fn(self: *Self)write the pairs, then end
Out.end
Section titled “Out.end”pub end :: fn(self: *Self)closes an indefinite array or map
Out.tag
Section titled “Out.tag”pub tag :: fn(self: *Self, t: u64)tags the next item (1 = epoch seconds, 32 = uri, …)
Out.boolean
Section titled “Out.boolean”pub boolean :: fn(self: *Self, v: bool)Out.null_value
Section titled “Out.null_value”pub null_value :: fn(self: *Self)Out.undefined
Section titled “Out.undefined”pub undefined :: fn(self: *Self)Out.simple
Section titled “Out.simple”pub simple :: fn(self: *Self, v: u8)0..19 or 32..255; anything else writes nothing
Out.float
Section titled “Out.float”pub float :: fn(self: *Self, v: f64)shortest exact width; NaN as half
Out.raw
Section titled “Out.raw”pub raw :: fn(self: *Self, b: []const u8)pre-encoded cbor, as is
Out.finish
Section titled “Out.finish”pub finish :: fn(self: *Self) -> void ! IoError.write_failed if any write failed
writer
Section titled “writer”pub writer :: fn(w: *Writer) -> OutReader
Section titled “Reader”pub Reader :: struct { data: []const u8, pos: usize,}one item at a time; a container’s items follow its header
Reader.at_end
Section titled “Reader.at_end”pub at_end :: fn(self: *Self) -> boolReader.next
Section titled “Reader.next”pub next :: fn(self: *Self) -> Item ! CborErrorReader.skip
Section titled “Reader.skip”pub skip :: fn(self: *Self) -> void ! CborErrorskips the next item and everything in it
Reader.skip_contents
Section titled “Reader.skip_contents”pub skip_contents :: fn(self: *Self, it: Item) -> void ! CborErrorskips what it (just read) holds: items, pairs, tagged item, string parts
reader
Section titled “reader”pub reader :: fn(data: []const u8) -> Reader