-
Notifications
You must be signed in to change notification settings - Fork 56
Multidecoder Interface #195
Copy link
Copy link
Open
Labels
P2Medium: Good to have, but can wait until someone steps upMedium: Good to have, but can wait until someone steps upexp/expertHaving worked on the specific codebase is importantHaving worked on the specific codebase is importanthelp wantedSeeking public contribution on this issueSeeking public contribution on this issue
Metadata
Metadata
Assignees
Labels
P2Medium: Good to have, but can wait until someone steps upMedium: Good to have, but can wait until someone steps upexp/expertHaving worked on the specific codebase is importantHaving worked on the specific codebase is importanthelp wantedSeeking public contribution on this issueSeeking public contribution on this issue
Right now -- I should say, from how I understand it --
js-multiformatsdefines an interface for encoding and decoding using individual codecs. This encapsulates the codec pattern perfectly well. In fact, for encoding, it's really all you need; seeing as you can only encode something using a single codec.However, when dealing with IPLD in the more general sense (which strives to be polymorphic over its serializations), developers are left on their own to create codec/hash registries that will hopefully be complete enough to be able to deserialize what's given to them.
This is especially exacerbated in the case of libraries which take CIDs from their users. Library authors have to either:
Obviously, the former of the two is an obvious antipattern. The latter, though, has been used successfully in many of the higher level JavaScript IPFS libraries to provide generic interfaces libraries can consume -- dependency injection.
I propose a similar interface, named something like a
PolyMultidecoderwhich exposes anadd()andremove()to (de)registerBlockDecoders, and a singledecode()which resolves and uses the correct decoder, or throws an error if it's otherwise missing.