helper methods for encoding and decoding #232
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add new helper methods that shorten up the number of keystrokes needed for common operations related to encoding and decoding.
These are added in the root
ipld
package, where new users of the library should find them quickly and easily. (This was made possible by #228 .)Many common operations are available, but of course not all of them -- for example, if one wants to control a NodeBuilder manually and use its Reset features for allocation avoidance on repeated use, you'd still have to dive deeper and these facades won't help you. But, at the same time, the sheer existence of these facades -- and their copious documentation about subjects exactly like that one! -- means users should find that easier than ever to learn how to do, if it becomes desirable to them to go there.
Some of these functions take shortcuts I never would've considered acceptable before. For example,
Encode
andDecode
in this diff... don't let you specify aNodePrototype
; nada. They just brazenly and directly usebasicnode.Prototype.Any
, without asking you about it. Aside from being physically possible now (e.g., without provoking an import cycle, which is again due to the work in #228), this also feels acceptable to me now, as we pivot the semantics of the root package of this repo to "these are where the helpful high-level and getting-started functions go".Similarly, I've directly exposed
ipld.Marshal
andipld.Unmarshal
functions, which provide quick access to some of the features ofbindnode
that a new user is most likely to want to use. The fullbindnode
package interface, and composing it with our other packages yourself, is still clearly more powerful. But having this facade -- which shows you where to find the rest of those features, and, if necessary, how to put them together yourself -- should still help first-time users enormously.You can see the ultimate impacts to what a user sees in the included new example functions. I think this is the first time I've been able to put example functions that actually look good in one of our central, the-user-sees-it-for-sure packages, and I'm really happy about this.