The tree is the file
Every row names its format byte (fixmap, uint32, float16, tag, indefinite text) and the range it occupies. Expand a map and each key keeps its own range beside its value, which is what makes a byte map possible at all.
Pikkola Msgpack, tool No. 73
Paste a MessagePack or CBOR payload as hex or base64 and read it two ways at once: a tree where every value carries its type tag and its byte range, and the JSON the payload stands for. Write it back from JSON, see exactly how many bytes each format saves, and take the file with you.
The studio
Three benches over the same value. The reader opens bytes, the writer turns JSON back into bytes, and the scale puts JSON, MessagePack and CBOR side by side. Nothing is sent anywhere.
| Type | Start to end | Length | Path |
|---|
No request, no account, no storage. The Content-Security-Policy sets connect-src to none, so the page could not upload a payload even if it tried. A payload can hold a session token, and this one stays in the text box.
JSON has no bytes, extensions or tags, so the reader writes them as an object with one known key. The writer reads the same shapes back, which makes a round trip lossless.
{"$bin": "AAEC"} | base64 bytes |
{"$int": "9007199254740993"} | a 64 bit integer as a string |
{"$ext": {"type": 2, "data": "AAEC"}} | a MessagePack extension |
{"$tag": {"tag": 1, "value": 1764115200}} | a CBOR tag around a value |
{"$undefined": true} | CBOR undefined |
{"$float": "NaN"} | NaN or an infinity |
{"$entries": [[1, "a"], [2, "b"]]} | a map whose keys are not all text |
Everything below comes from the JSON in the writer bench. Change it there and the scale follows.
| Encoding | Bytes | Against indented JSON | Share of the JSON |
|---|
| Type | MessagePack | CBOR |
|---|
MessagePack and CBOR carry the same value in different shapes: a type in the first byte, then the length, then the payload. CBOR can also say undefined, tag a value and split a long string into chunks.
A decoder that hands back a plain object throws the offsets away. This one keeps them, so a value can be pointed at in the hex dump and a field can be traced from its first byte to its last.
Every row names its format byte (fixmap, uint32, float16, tag, indefinite text) and the range it occupies. Expand a map and each key keeps its own range beside its value, which is what makes a byte map possible at all.
A byte string, an extension, a tag, an undefined and an integer past 2^53 have no JSON spelling. They come out as an object with one known key, and the writer reads the same shape back, so decoding and encoding again gives the same bytes.
A small integer takes one byte in both formats. Text under 32 bytes is a fixstr in MessagePack and one header byte in CBOR. A float that is exact in half precision is written in two bytes; one that is not goes up to single or double precision.
Both put a type and a length in front of the payload and both grow a byte at a time. The tables are the whole vocabulary the reader understands.
| First byte | Meaning |
|---|---|
positive fixint, 0x00 to 0x7f | the integer itself, one byte |
negative fixint, 0xe0 to 0xff | the integer itself, one byte, below zero |
uint8 to uint64, int8 to int64 | signed and unsigned integers up to 8 bytes |
float32, float64, 0xca and 0xcb | IEEE 754 in 4 or 8 bytes |
fixstr, 0xa0 to 0xbf | text of up to 31 bytes |
str8, str16, str32, array16, array32, map16, map32 | the long forms, for anything past the fixed range |
fixmap, 0x80 to 0x8f, fixarray, 0x90 to 0x9f | map or array of up to 15 entries |
nil, false, true, 0xc0 to 0xc3 | null and the two booleans |
bin8, bin16, bin32, 0xc4 to 0xc6 | raw bytes with a 1, 2 or 4 byte length |
ext8, ext16, ext32, fixext1 to fixext16 | an application type byte and its payload |
0xc1 | reserved, never used |
| First byte | Meaning |
|---|---|
major 0, unsigned integer | the value itself, up to 8 bytes |
major 1, negative integer | minus one minus the value |
major 2, byte string | raw bytes, optionally in indefinite chunks |
major 3, text string | UTF-8 text, optionally in indefinite chunks |
major 4, array | items in order, optionally until a break |
major 5, map | key and value pairs, any key type |
major 6, tag | a number that says what the next value means |
major 7, simple and float | false, true, null, undefined, half, single, double, break |
No. Both readers and both writers are functions in JavaScript files on this domain, and the Content-Security-Policy sets connect-src to none, so the page could not upload a byte even if it tried. It also works with the network off after the first load.
MessagePack as specified at github.com/msgpack, and CBOR as defined in RFC 8949, including indefinite lengths, tags, half precision floats and 64 bit integers. It does not read the schema based formats: Protobuf needs a schema, and this tool has none.
Both formats start with a byte that says type and length, and the same byte can mean different things in each. 0x82 is a two entry map in MessagePack and a two item array in CBOR. Detection reads the whole payload both ways and leans on the markers only one format writes, but when the bytes are truly ambiguous you can pick the format yourself.
A byte string is {"$bin": "base64"}, a MessagePack extension is {"$ext": {"type": 2, "data": "base64"}}, a CBOR tag is {"$tag": {"tag": 1, "value": 1764115200}}, an integer past 2^53 is {"$int": "9007199254740993"}, and CBOR undefined is {"$undefined": true}. The writer reads each of them back, so nothing is lost between the two.
They are the bytes each encoder actually wrote, and JSON is measured as UTF-8 text with the indentation shown. MessagePack and CBOR usually win on numbers and short repeated keys, but a payload of long unique strings saves almost nothing: text is copied byte for byte in all three.
No. It reads bytes, not meaning. A field called hp is an integer here; whether 87 is a legal hit point is the application's business. Use it to see what a payload holds, to check an encoder you are writing, or to compare the cost of two encodings.