document recommendations for multicodec implementations
While trying to resurrect a Go implementation (since go-multicodec is deprecated and archived), I went through multiple phases of what a multicodec library should look like. Only after talking to other members of the IPLD team I came to the conclusion that many of my initial ideas weren't great.
For example, exposing the entire table in an implementation is a bad idea. The table will grow over time, so it will mean higher costs such as memory usage, binary size, and compile time.
Similarly, categorizing the names or codes is not a good idea. The table has a tag field, but it doesn't mean that each of the codes fits neatly into a single category which will remain stable over time. I initially had the idea to give named constants different types in Go to separate the categories and avoid using the wrong type of code, but that turns out to be a bad idea.
Another pitfall would be to implement all of the multicodecs as part of the library, such as via external dependencies. This would mean that importing the multicodec library would suddenly pull hundreds of indirect dependencies, whereas the user likely only needs a tiny minority.
So it seems like the general recommendation should be to just expose a series of named constants for each of the codes. For example, in Go, we could simply code generate:
package multicodec
const (
Identity = 0x00 // raw binary
CIDv1 = 0x01 // CIDv1
[...]
The main advantage here would be that code would be self-explanatory; instead of having:
Codec: 0x71, // dag-cbor
we'd have just:
Codec: multicodec.DagCBOR,
I think this could be a brief section under "Implementations". I imagine that the general recommendations would apply to most languages.
package multicodec
const ( Identity = 0x00 // raw binary CIDv1 = 0x01 // CIDv1 [...]
Did you mean package ipldcodec? If yes, this the problem outlined at https://github.com/ipld/specs/issues/288.
I'm not sure. This list of constants would correspond to the entire list in the multicodec spec, which is why I was assuming that go-multicodec should be called package multicodec. Calling it ipldcodec would be a bit inconsistent given what the other libraries in the rest of the languages are called, no?
@mvdan sorry, I misread the original issue. Just ignore my comment, what you say makes sense.
Though I'm still not sure (as in "really not sure" and not in "don't do that") if there should even be a package containing all constants.