-
Notifications
You must be signed in to change notification settings - Fork 758
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
CBOR support #163
Comments
@pyfisch: I'd be fine if you want to have CBOR be a part of serde-rs. Have you and @BurntSushi figured out if you can consolidate your projects? On tags, I was struggling as well to figure out a good way to express them when I ported https://github.com/BurntSushi/rust-cbor over to serde. I did a terrible hack where I inspected the struct name and did something special with that, but I wasn't particularly happy with that approach. Having a |
I already compared my code to the implementation by @BurntSushi. The code is very similiar but rust-cbor uses an intermediate syntax while serde-cbor directly deserializes the values. We did not yet discuss if we can cosolidate projects. I would need |
I have clearly dropped the ball on using I have two suggestions:
|
|
@pyfisch RE 2: No, I can't. :-( The only thing I can say is that when I was writing |
@pyfisch / @BurntSushi: Do you think it would ever make sense to factor out the cbor parser and serializer from |
@erickt If you look at my cbor crate, there is some code sharing, but I mostly failed to reuse code between parsing CBOR into an algebraic data type and decoding directly in |
I'm not sure exactly how all of this code is structured but I'd like to point out that I think on the decoding side the tag has to be able to change (or possibly stack) the visitor used downstream of itself, so perhaps there needs to be a map somewhere between tag values and visitors. In some sense this can be considered similar to differentiating maps from sequences, since a map is really just a special interpretation of a sequence (even number of elements, alternating keys and values). As a complicated example of a tag consider http://cbor.schmorp.de/stringref. In this case tag 256 declares that every string (text or byte) contained within the tag will be indexed and any tag 25 will contain exactly an integer which is an index into the string table. This means that when the tag 256 is seen then the visitor needs to be wrapped with one that can inspect every other string decoding so that it can build its table. If another tag 256 is encountered then the previous one needs to be occluded until the inner one is finished and then the outer one is restored. |
The tagging discussion is continued in #455. It looks like the solution will be specialization as @BurntSushi guessed. |
Update num_macros to current nightly Fixes num_macros build for current nightly, broken by [this](https://github.com/rust-lang/rust/pull/31487/files) PR on rust.
I have written a CBOR serialization and deserialization crate for serde. The conforms to the CBOR spec, is tested and documented. Is it possible to move it to the serde-rs organization? I would also really like to hear some code review.
Serde supports annotations to values to assign a special meaning. For example the tag 32 is used to annotate URIs. To support these tags within serde a method for
serde::de::Visitor
to for tags would be useful. The signature could be something likefn visit_tag<D>(&mut self, tag: u64, _deserializer: &mut D) -> Result<Self::Value, D::Error>
and default to ignoring the tag and just visit the inner value. There could be a similiar method forser::Serializer
.The text was updated successfully, but these errors were encountered: