-
Notifications
You must be signed in to change notification settings - Fork 63
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
feature: CBOR sequences #362
Comments
Looks like you can do this by creating an encoder using Easiest way is to use package level encoder := cbor.NewEncoder(w)
err := encoder.Encode(v) If you need custom options, you can create opts := cbor.CoreDetEncOptions() // Use modern options. You can customize the returned opts.
em, err := opts.EncMode() // This creates reusable encoding mode (safe for concurrency).
encoder := em.NewEncoder(w) // Create encoder with io.Writer.
err := encoder.Encode(msg1) // Use encoder to send data to underlying io.Writer.
err = encoder.Encode(msg2) // Use encoder to send data to underlying io.Writer. For security, you can use There's more info and examples at https://github.com/fxamacker/cbor/#quick-start |
Ok thank you very much, I made it work both with reader and marshall:
One last use case covered by NDJSON and CBOR sequences, which is stream parsing: let's say I have 5 messages in my file, and I want to read the 4th without parsing the first 3, is it possible with this approach? Should I maybe build a custom decoder, read only the length at the beginning, and then skip to the next position in the buffer? Does CBOR prepend the length of the full message? |
CBOR doesn't define "full message". If you meant "data item" as defined in CBOR RFC 8949, then some data items like CBOR Array will have number of elements (but not size of entire array in bytes). @fxamacker what do you think of adding a Skip feature to Decoder that allows skipping next data item? |
At a glance, CBOR Sequence (RFC 8742) is just a concatenation of zero or more encoded CBOR data items, without markers in between nor at the end. CBOR data items are defined in Section 1.2 of RFC 8949.
As @x448 mentioned, if by "full message" you meant CBOR "data item" as defined in RFC 8949, then I can add a Skip feature to the decoder. CBOR doesn't prepend length (size in bytes) of data item.
It sounds like you want to "skip" the first 3 messages and then parse the 4th message. Skip isn't currently supported by
One more thing, I noticed |
I think this issue can be closed because the original request is already supported by this CBOR codec. The Skip() feature request is in the newly opened issue #366. |
@x448 @fxamacker I actually meant to skip a message (data item?) in a sequence. I thought it was covered by this part of the spec. Will |
Is your feature request related to a problem? Please describe.
I would like to append multiple CBOR messages to a file
Describe the solution you'd like
Ideally I would like CBOR sequences, or a practical way to decode multiple messages to a file.
Describe alternatives you've considered
At the moment I'm using NDJSON, but it's a pain
Additional context
Spec
The text was updated successfully, but these errors were encountered: