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

helper methods for encoding and decoding #232

Merged
merged 1 commit into from
Aug 19, 2021
Merged

helper methods for encoding and decoding #232

merged 1 commit into from
Aug 19, 2021

Conversation

warpfork
Copy link
Collaborator

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 and Decode in this diff... don't let you specify a NodePrototype; nada. They just brazenly and directly use basicnode.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 and ipld.Unmarshal functions, which provide quick access to some of the features of bindnode that a new user is most likely to want to use. The full bindnode 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.

…d for common operations related to encoding and decoding.
@warpfork
Copy link
Collaborator Author

@willscott , you should also love this -- with these, I finally add the "automatically gearshift into representations the instant we get a whiff of typed nodes" feature.

I'm also happy, because by adding it here in a facade, we leave the possibility for a user to dive into the deeper packages, and do things like apply codecs directly to other layers... if they want, and if they know what they're doing. But the first and most obvious functions to reach for... will now "DTRT". (And hopefully teach people about it, since the docs on those functions touch on this behavior, too.)

Copy link
Member

@willscott willscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I do like this addition!

@warpfork warpfork merged commit a47ecf9 into master Aug 19, 2021
@warpfork warpfork deleted the codec-facades branch August 19, 2021 22:58
@rvagg
Copy link
Member

rvagg commented Aug 20, 2021

ENEEDSMORETESTS

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

Successfully merging this pull request may close these issues.

3 participants