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

Support for fragment encoding #244

Open
RomainPelletant opened this issue Jul 29, 2022 · 5 comments · May be fixed by #424
Open

Support for fragment encoding #244

RomainPelletant opened this issue Jul 29, 2022 · 5 comments · May be fixed by #424
Labels
enhancement New feature or request

Comments

@RomainPelletant
Copy link

As for decoder with the zcbor_bstr_start_decode_fragment function to only read the CBOR header in case of block-wise (COAP) transfer, it could be interesting to create the same capability in encoder to only encode partial data into several fragments and set the header only once.

@oyvindronningstad
Copy link
Collaborator

oyvindronningstad commented Aug 2, 2022

The problem is that the encoder doesn't know the byte count until the end of the string. We could consider adding new APIs to used when the byte count is known beforehand.

Thanks for the suggestion, will look into this in the future.

@escherstair
Copy link

I think this request is almost the same as one of my needs, that in other libraries is called streaming array. See as an example libcbor.
This is useful when you have large arrays or maps and either their size is known in advance, or they are indefinite (see here).
With "streaming encoding" you can encode them on the fly and strem them over the network (as an example) without having to allocate a CBOR buffer large enough.

(With a different CBOR library) I implemented this feature by myself (simplified version), but I'm not satisfied about the API I created.

@oyvindronningstad
Copy link
Collaborator

@escherstair Have you looked into zcbor_update_state()?

@escherstair
Copy link

I have to investigate and understand how it works

@mlasch
Copy link

mlasch commented Jul 18, 2023

Such a feature might be an interesting addition. I had to implement generating the CBOR part (serializing CBOR header, then appending opaque on the fly) myself, in order to send a big opaque LwM2M resource block-wise in SenML-CBOR.
The data structure looks like this, size of bytes is known in advance:

[{-2: "/32765/0/", 0: "9", 8: h'313233'}]
81                          # array(1)
   A3                       # map(3)
      21                    # negative(1)
      69                    # text(9)
         2F33323736352F302F # "/32765/0/"
      00                    # unsigned(0)
      61                    # text(1)
         39                 # "9"
      08                    # unsigned(8)
      43                    # bytes(3)
         313233             # "123"

@oyvindronningstad oyvindronningstad added the enhancement New feature or request label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants