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

feat: add Context to EncodeBuffer and DecodeBuffer #90

Merged
merged 1 commit into from
Oct 5, 2022
Merged

Conversation

tjjfvi
Copy link
Owner

@tjjfvi tjjfvi commented Oct 5, 2022

This allows codecs to store state for a given encode/decode run:

class FooCtx {
  fooCounter = 123;
}
const $foo = createCodec({
  ...
  _encode(buffer, value){
    ...
    const ctx = buffer.context.get(FooCtx);
    ctx.fooCounter;
    ...
  },
  ...
});

This can be used to encode/decode recursive structures – in particular, this will allow us in Capi to decode FRAME metadata in a recursive structure, rather than with the indices.

Copy link
Contributor

@harrysolovay harrysolovay left a comment

Choose a reason for hiding this comment

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

This is a very exciting one.

@tjjfvi tjjfvi merged commit 73c76a4 into main Oct 5, 2022
@tjjfvi tjjfvi deleted the codec-context branch October 5, 2022 15:34
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.

2 participants