Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document recommendations for multicodec implementations #199

Open
mvdan opened this issue Sep 24, 2020 · 3 comments
Open

document recommendations for multicodec implementations #199

mvdan opened this issue Sep 24, 2020 · 3 comments

Comments

@mvdan
Copy link

mvdan commented Sep 24, 2020

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.

@vmx
Copy link
Member

vmx commented Sep 25, 2020

package multicodec

const (
Identity = 0x00 // raw binary
CIDv1 = 0x01 // CIDv1
[...]

Did you mean package ipldcodec? If yes, this the problem outlined at ipld/specs#288.

@mvdan
Copy link
Author

mvdan commented Sep 25, 2020

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?

@vmx
Copy link
Member

vmx commented Sep 25, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@vmx @mvdan and others