-
Notifications
You must be signed in to change notification settings - Fork 915
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
refactor(experimental): add addCodecSentinel to @solana/codecs-core #2419
Conversation
🦋 Changeset detectedLatest commit: d9c019d The changes in this PR will be included in the next version bump. This PR includes changesets to release 35 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @lorisleiva and the rest of your teammates on Graphite |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! How might one chain sentinel codecs together?
Also, how come this is named in reverse order of the other codecs, like ArrayCodec
and MapCodec
. Here it's reversed (CodecSentinel
). Assuming because of the nature of the sentinel coming after the codec bit? Since this still produces a valid codec, it did throw me off a bit.
7aec5eb
to
22826af
Compare
Hey @buffalojoec, Regarding chaining sentinelsYou can just use any other codec to chain them such as const sentinel = new Uint8Array([255]);
const person = getStructCodec([
['firstname', addCodecSentinel(getUtf8Codec(), sentinel)],
['lastname', addCodecSentinel(getUtf8Codec(), sentinel)],
['age', getU8Codec()],
]);
person.encode({ age: 42, firstname: 'John', lastname: 'Doe' });
// 0x4a6f686eff446f65ff2a
// | | └-- Age.
// | └-- Lastname.
// └-- Firstname. I added a couple of tests to illustrate that. Regarding codec naming conventionsThere is a difference between primitive functions like Whilst all codec functions start with a verb, there are two categories of codec functions: the codec primitives and the codec type helpers. Codec primitivesThese functions are lower-level helper and live under the The naming convention for codec primitives is to describe that codec manipulation by starting with a verb. For instance:
Codec type helpersOn the other hand, codec type helpers are meant to provide codecs for specific types and live under the other codec packages such as The naming convention for codec type helpers is
Now, with this in mind, does EDIT: Re-reading this message, I now realised it could be interpreted as a very cold response with a mean rhetorical question at the end. Please know that it wasn't meant that way and that final question is genuine and written with care not anger. I sincerely apologise for the lack of tone in my reply which makes it possible to interpret it that way. |
Sorry, just circling back to this. Yeah, I think with that provided context this does seem like a proper name. Maybe it's because I didn't know about |
22826af
to
d9c019d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Merge activity
|
🎉 This PR is included in version 1.91.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
This PR adds a new
addCodecSentinel
primitive.The
addCodecSentinel
function provides a new way of delimiting the size of a codec. It allows us to add a sentinel to the end of the encoded data and to read until that sentinel is found when decoding. It accepts any codec and aUint8Array
sentinel responsible for delimiting the encoded data.