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

decodeFirst() #93

Merged
merged 3 commits into from
Sep 11, 2023
Merged

decodeFirst() #93

merged 3 commits into from
Sep 11, 2023

Conversation

rvagg
Copy link
Owner

@rvagg rvagg commented Sep 11, 2023

For both CBOR and JSON decoders. const [value, remainder] = decodeFirst(buf). Where remainder is a subarray, so just a view over the original ArrayBuffer.

import { decodeFirst } from 'cborg'

let buf = Buffer.from('a16474686973a26269736543424f522163796179f564746869736269736543424f522163796179f5', 'hex')
while (buf.length) {
  const [value, remainder] = decodeFirst(buf)
  console.log('decoded:', value)
  buf = remainder
}
decoded: { this: { is: 'CBOR!', yay: true } }
decoded: this
decoded: is
decoded: CBOR!
decoded: yay
decoded: true

This is a breaking change because the Tokenizer interface now needs to implement pos() which was previously just implemented as an internal detail but now we need to know where the tokenizer is up to in order to implement this.

BREAKING CHANGE

Implementations of `Tokenizer` must now implement a pos() method to be
compatible. This should only impact advanced users of cborg.

Ref: #75
This was referenced Sep 11, 2023
@rvagg rvagg merged commit 06133db into master Sep 11, 2023
27 checks passed
@rvagg rvagg deleted the rvagg/decodeFirst branch September 11, 2023 23:40
@github-actions
Copy link

🎉 This PR is included in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant