Skip to content

Conversation

@lorisleiva
Copy link
Member

@lorisleiva lorisleiva commented Nov 4, 2024

This PR adds a new dynamic-codecs package that allows us to create Codec instances on demand (as defined in @solana/codecs) from Codama nodes.

This package is a bit low-level since the intention is for it to be used inside another dynamic-parsers package which will be created shortly after this PR is merged. The goal of the dynamic-codecs package is to focus on the foundations of creating codecs for any nodes.

Namely, it offers a getNodeCodec function that, given the full NodePath of a node, returns a Codec<unknown> that enables encoding and decoding data for that node. Here's an example:

const codec = getNodeCodec([root, program, definedType]);
const bytes = codec.encode(someData);
const decodedData = codec.decode(bytes);

See the README of the new package for more information.

@changeset-bot
Copy link

changeset-bot bot commented Nov 4, 2024

🦋 Changeset detected

Latest commit: 0591177

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@codama/dynamic-codecs Minor

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

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @lorisleiva and the rest of your teammates on Graphite Graphite

@lorisleiva lorisleiva force-pushed the loris/dynamic-codecs branch 5 times, most recently from 00bba59 to 71b0830 Compare November 4, 2024 17:45
@lorisleiva lorisleiva changed the title Add dynamic-codecs package Add dynamic-codecs package Nov 4, 2024
@lorisleiva lorisleiva force-pushed the loris/dynamic-codecs branch 11 times, most recently from 8a805f1 to d0fdc21 Compare November 5, 2024 15:46
@lorisleiva lorisleiva marked this pull request as ready for review November 5, 2024 15:53
@lorisleiva lorisleiva requested review from febo and ngundotra November 5, 2024 15:54
Copy link
Member Author

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

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

Quick self-review

@lorisleiva lorisleiva force-pushed the loris/dynamic-codecs branch from d0fdc21 to 0591177 Compare November 5, 2024 17:59
Copy link

@ngundotra ngundotra left a comment

Choose a reason for hiding this comment

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

LGTM! Looking forward to dynamic-parsers package!

@lorisleiva lorisleiva merged commit 9b8b795 into main Nov 5, 2024
4 checks passed
@lorisleiva lorisleiva deleted the loris/dynamic-codecs branch November 5, 2024 20:25
@github-actions github-actions bot mentioned this pull request Nov 4, 2024
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