-
Notifications
You must be signed in to change notification settings - Fork 64
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
feat: Value
representation of Simple
values
#137
Conversation
78fd705
to
19fafba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this expected to change the API from the user's perspective?
} | ||
} | ||
|
||
pub(crate) struct Serializer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are all the functions for Serializer
returning an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only function returning Ok
is serialize_u8
, which is the only legal content of a simple value. It is used in ciborium/src/ser/mod.rs (Serializer::serialize_newtype_struct
)
I would think that's something for ciborium_ll. |
This PR? No. The WIP Packed CBOR impl? Not at the moment. At its current state we simply added new functions for packed cbor. |
A few of the |
You mean any tests beyond the four mentioned in the PR? |
No, sorry; I forgot about those four. |
… values Signed-off-by: Emanuel Pilz <[email protected]>
f37029b
to
7da33fe
Compare
Co-authored-by: Hendrik Wolff <[email protected]> Co-authored-by: Theodor Straube <[email protected]> Co-authored-by: moehr1z <[email protected]> Signed-off-by: Emanuel Pilz <[email protected]>
7da33fe
to
5bd0c85
Compare
Having simple values as a separate Value variant is a major strategic direction change for this crate. I'm not sure it makes sense. |
@emonadeo I really don't understand what you're suggesting here. |
I need to parse and produce This PR is definitely not ready to merge and requires more testing for edge cases (like deserializing a Value into a Value, which is silly, but technically legitimate), but I think in concept it's necessary unless you want to limit ciborium to plain CBOR. |
@emonadeo But what is the semantic meaning of |
Oh, do they? Tags also aren't semantic and they have a Value representation.
It doesn't have an immediate semantic value. Packed CBOR uses I don't think it's possible to implement Packed CBOR on top of Ciborium without a way to deserialize Simple values. Adding representation of Simple values opens up more possibilities to use Ciborium for „extension protocols“ as with the case of Packed CBOR. |
Tags are at least semi-semantic. They contain a hint as to the proper usage of the following type.
I'll be really honest, when I read the Packed CBOR RFC, it very much strikes me as a solution in search of a problem. It has only two authors, both in academia. It solves a problem that can be easily solved by just gzipping the cbor. It solves the problem in a way that significantly complicates encoding. And it solves the problem less efficiently than a good compression algorithm. Here's the main paragraph:
Which use cases are hesitant to decompress the CBOR before using it? The industry has reliable, battle-hardened and highly optimized compression algorithms and implementations. And further, they can be implemented at the transport layer, so applications don't need to even think about this detail. I just don't "get it". Perhaps it is because I'm dense. Can you give me a concrete case where packed CBOR is an essential feature? |
No idea if this is essential, probably not. I just think it's fun to implement. As a matter of fact the four of us are students working on this as a research project. We thought it would be nice to contribute to a library rather than creating another piece of academic abandonware. Don't feel pressured to agree to these changes. |
@emonadeo I definitely don't want to expose I spent some time reading on the packed CBOR proposal today. My findings aren't really positive.
That being said, I'm willing to see a patch against the serializer and deserializer to enable a "packed" mode. I'd like to see how invasive it is. The application would need to opt-in to packed mode. Likewise, I'd want packed mode behind a feature flag so that we can rip it out. But it is not a goal of the ciborium crate to enable a separate crate to implement packed mode. And we are definitely not going to add |
Currently Simple values are not representable as a Value type.
We (@emonadeo, @hw0lff, @TheodorStraube, @moehr1z) are working on a Packed CBOR implementation based on ciborium, which relies on tags and simple values.
This PR adds a
Simple
variant to theValue
enum.Changes
The changes basically boil down to the following:
pub enum Value { Integer(Integer), Bytes(Vec<u8>), Float(f64), Text(String), Bool(bool), Null, Tag(u64, Box<Value>), Array(Vec<Value>), Map(Vec<(Value, Value)>), + Simple(u8), }
In order to serialize
Value::Simple(u8)
,serialize_newtype_struct
and hardcoded@@SIMPLE@@
markers are used (similar to how it is done with Tags)This works, but is admittedly not great. Potential other ideas here are appreciated.
RFC: Forbidden two-byte encodings of one-byte simple values:
4 tests are failing at the moment:
These are testing
simple(0)
,simple(1)
,simple(24)
andsimple(31)
respectively.While syntactically correct, the CBOR Specification states:
(This also means that
simple(24)
can never exist, asf818
is not valid andf8
by itself denotes the use of an additional byte. Likewisesimple(25)
..simple(31)
cannot exist, because they are either floats, reserved, or a break stop code).We intentionally left this unfixed, as we are not sure if this should be caught in the decoder of ciborium_ll, or at a higher level in ciborium.
RFC: Replace
Bool
andNull
variants withSimple
constantsWe originally removed the
Bool
andNull
variants and replaced them with constants, since these are technically alsoSimple
values:However removing these would introduce a breaking change. As such we figured a redundant representation of
false
(Value::Bool(false)
orValue::Simple(20)
),true
(Value::Bool(true)
orValue::Simple(21)
) andnull
(Value::Null
orValue::Simple(22)
) makes more sense in order to both not break compatibility and preserve ergonomics.Footnotes
https://www.rfc-editor.org/rfc/rfc8949.html#section-3.3-5 ↩