Skip to content
lerno edited this page Sep 12, 2011 · 3 revisions

Self-describing protocols are useful for several different tasks. One is informal protocols, another is when encapsulating arbitrary structures in a formal protocol.

Argos is just one recipe for compressing such data.

Protocol

Prefix

 00-7F integer 0-127

 80    boolean FALSE
 81    boolean TRUE

 82    double 0.0
 83    8 byte double

 84    date using 8 bytes (ms since epoch)
 85    date using 5 bytes (s since epoch, safe to year 19391)
 86    date using 3 bytes (h since epoch, safe to year 2926)

 87    integer -1
 88-8F signed 1 to 8 byte integer

 90-9D 0-14 byte length string (UTF-8)
 9E    string 0-255 bytes (UTF-8)
 9F    string 256-65535 bytes (UTF-8)

 A0-AD 0-14 entry length array
 AE    array 0-255 entries
 AF    array 255-65535 entries

 B0-BD 0-14 entry map
 BE    map 0-255 entries
 BF    map 255-65535 entries

 C0-ED symbol 0-45
 EE    symbols 46-301

 EF    null / nil

 F0-FD byte array 0-14 bytes
 FE    byte array 0-255 bytes
 FF    byte array 0-65535 bytes

Examples

A mixed value object

{"a": 1, "b": [11, 22, 33], "c": null }

Compressed JSON:
7B 22 61 22 3A 31 2C 22 62 22 3A 5B 31 31 2C 32 32 2C 33 33 5D 2C 22 63 22 3A 6E 75 6C 6C 7D (31 bytes)

Argos (first pass):
B3 C0 01 62 A3 0B 16 21 C1 01 63 EF C2 01 61 01 (16 bytes)

Argos (second pass - interned symbols):
B3 C0 A3 0B 16 21 C1 EF C2 01 (10 bytes)

Int arrays

[1, 20, 255, 1000, 65536]

Compressed JSON:
5B 31 2C 32 30 2C 32 35 35 2C 31 30 30 30 2C 36 35 35 33 36 5D (21 bytes)

Argos:
A5 01 14 88 7F 89 03 E8 8A 01 00 00 (12 bytes)

Conventional typed int array:
05 00 00 00 01 00 00 00 14 00 00 00 FF 00 00 03 E8 00 01 00 00 (21 bytes)

For small int values (a common scenario):

[11, 33, 0, 55, -11]

Compressed JSON:
5B 31 31 2C 33 33 2C 30 2C 35 35 2C 2D 31 5D (15 bytes)

Argos:
A5 0B 21 00 37 88 F5 (7 bytes)

Smallest possible optimized byte array: 05 0D 21 00 37 F5 (6 bytes)