Open artemii235 opened 5 years ago
A couple of extra options to the mix:
We're using a bit of https://en.wikipedia.org/wiki/Bencode with libtorrent and I like the compactness and the nice property of it having a single binary representation (the bijection property), useful for duplicate detection and caching. Though it's a bit more restrictive than JSON.
For simple stuff there are also netstrings, e.g. the example above might be encoded as a list of key-value pairs: 6:method,6:notify,6:rmd160,11:...,3:pub:,32:...,
I should also mention zstandard compression which we're now using with HTTP fallback. It supports a static dictionary, allowing us to remove the overhead of keys (like the "method", "notify", "rmd" and "pub" keys above). zstandard allows us to use JSON (to which CRDTs in HTTP fallback are limited) with a close-to-binary size efficiency. P.S. Though zstandard isn't readily portable.
I think we should consider switching from rmp_serde
to either another binary protocol like protobuf or some human-readable text protocol like Json.
It becomes hard to add new fields to messages, and sometimes it requires the use of crutches like this https://github.com/KomodoPlatform/atomicDEX-API/issues/1487
cc: @artemii235
JSON is too "fat" for such purpose, e.g.
notify
messagecontains
rmd160
,pub
,pubsecp
,sig
fields which are bytes sequence encoded in hex - it makes the message almost2x
larger not providing any real benefit. So switching to somebinary
format might help us to decrease the message sizes significantly which will be the most important for mobile users. The requirements are:As of now I see following options:
proto
structs to Rust, e.g.libp2p
is full of such scripts