rust-embedded-community / serde-json-core

`serde-json` for `no_std` programs
Apache License 2.0
161 stars 59 forks source link

Support for "block-wise" serialization? #66

Closed JKRhb closed 1 year ago

JKRhb commented 2 years ago

Firstly, thanks for providing this crate :)

Using the crate in the context of CoAP (the Constrained Application Protocol, RFC 7252), it would be nice if you could serialize structs in a "block-wise" manner, i.e., in chunks of a certain byte-size, where the position of the chunk "window" could be chosen arbitrarily.

This would not only allow for an easier implementation of CoAP block-wise transfer (see RFC 7959), but also save some memory on constrained devices as you would only need to have a buffer of that specific size for the result, presumably at a higher computational cost for the serialization overall, as you would need several runs for the moving window, supposing that you cannot begin where you left off after the previous one.

Do you think it would be possible to add a feature like this or accept a PR? Or would you consider it out of scope of this crate?

ryan-summers commented 1 year ago

Sorry for the super late reply, but I would personally see this as beyond the scope of what serde-json-core is supposed to do (serialize and deserialize JSON without std). Perhaps you could update the serializer/deserializer to operate on data streams instead of buffers and this would solve your use case. Now that the serializer and deserializer are public, I think this is actually relatively easy to do

JKRhb commented 1 year ago

Hi @ryan-summers, thank you for your feedback on this! :) I will have a look into it and will mark this issue as resolved :)