Skip to content
This repository has been archived by the owner on Mar 13, 2020. It is now read-only.

Structs' fields should be serialized in lexicographical order #4

Open
gsomix opened this issue Mar 2, 2020 · 4 comments
Open

Structs' fields should be serialized in lexicographical order #4

gsomix opened this issue Mar 2, 2020 · 4 comments

Comments

@gsomix
Copy link

gsomix commented Mar 2, 2020

Structs are encoded as dictionaries, so fields' names (keys) should be serialized in the in lexicographical order. In accordance with specification:

For each possible (complex) value, there is only a single valid 1coding; i.e. there is a bijection between values and their encodings.
...
A dictionary is encoded as d<contents>e. The elements of the dictionary are 1coded each key immediately followed by its value. All keys must be byte strings and must appear in lexicographical order.

@humb1t
Copy link
Contributor

humb1t commented Mar 3, 2020

@gsomix thanks, will fix the order. What about only a single valid coding, I don't think we can reach it for all languages. This guarantee works well only for theoretical types described in spec.

@humb1t
Copy link
Contributor

humb1t commented Mar 3, 2020

@humb1t
Copy link
Contributor

humb1t commented Mar 3, 2020

impl<'a> ser::SerializeMap for &'a mut Serializer and impl<'a> ser::SerializeStruct for &'a mut Serializer { should preserve order.
To do so - we need to add more fields to Serializer struct and "flush" into result string in the end of the struct (e char)

@humb1t
Copy link
Contributor

humb1t commented Mar 4, 2020

https://github.com/serde-rs/json - Compound type should be used

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants