Compact self-describing codecs. Save space by using predefined multicodec tables.
Table of Contents
- How does it work? - Protocol Description
- Multicodec table
Protocol Description - How does the protocol work?
multicodec is a self-describing multiformat, it wraps other formats with a tiny bit of self-description. A multicodec identifier may either be a varint (in a byte string) or a symbol (in a text string).
A chunk of data identified by multicodec will look like this:
<multicodec><encoded-data> # To reduce the cognitive load, we sometimes might write the same line as: <mc><data>
Another useful scenario is when using the multicodec as part of the keys to access data, example:
# suppose we have a value and a key to retrieve it "<key>" -> <value> # we can use multicodec with the key to know what codec the value is in "<mc><key>" -> <value>
Multicodec uses "protocol tables" to agree upon the mapping from one multicodec code. These tables can be application specific, though -- like with other multiformats -- we will keep a globally agreed upon table with common protocols and formats.
The full table can be found at table.csv inside this repo. Codes
0x are varint multicodecs and all others are symbolic.
Adding new multicodecs to the table
The process to add a new multicodec to the table is the following:
- Fork this repo
- Update the table with the value you want to add
- Submit a Pull Request
This "first come, first assign" policy is a way to assign codes as they are most needed, without increasing the size of the table (and therefore the size of the multicodecs) too rapidly.
Multicodec defines a table for the most common data serialization formats that can be expanded overtime or per application bases, however, in order for two programs to talk with each other, they need to know before hand which table or table extension is being used.
In order to enable self descriptive data formats or streams that can be dynamically described, without the formal set of adding a binary packed code to a table, we have
multistream, so that applications can adopt multiple data formats for their streams and with that create different protocols.
Q. I have questions on multicodec, not listed here.
That's not a question. But, have you checked the proper multicodec FAQ? Maybe your question is answered there. This FAQ is only specifically for multicodec.
Because multistream is too long for identifiers. We needed something shorter.
Q. Why varints?
So that we have no limitation on protocols. Implementation note: you do not need to implement varints until the standard multicodec table has more than 127 functions.
Q. What kind of varints?
An Most Significant Bit unsigned varint, as defined by the multiformats/unsigned-varint.
Q. Don't we have to agree on a table of protocols?
Yes, but we already have to agree on what protocols themselves are, so this is not so hard. The table even leaves some room for custom protocol paths, or you can use your own tables. The standard table is only for common things.
Q. Why distinguish between bytes and text?
For completeness, we consider multibase prefixes to be multicodecs. However multibase prefixes occur in text, and are therefore symbols. They may (or may not) have some underlying binary representation but that changes based on the text encoding used.
Contributions welcome. Please check out the issues.
Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.
Small note: If editing the README, please conform to the standard-readme specification.