serde-json-core
serde-json-core copied to clipboard
Draft - De-Escaping strings using a provided buffer
trafficstars
Here's a partial implementation of the design suggested in https://github.com/rust-embedded-community/serde-json-core/issues/79#issuecomment-2053622260_
How about the following design?:
- The deserializer takes a shared &str, as per the design before this pull request.
- When deserializing JSON strings, the deserializer scans for escape sequences
- If there are no escape sequences, it calls
visitor.visit_borrowed_str(v), which will allow zero-copy deserialization- If there are escape sequences, it decodes the escape sequence using a provided buffer, and calls
visitor.visit_str(v)serde_json_corehas aEscapedStringnewtype struct which contains an escaped&str, with utility methods to iterator over it, where the iterator returns either a&strof characters with no escape sequences, or an unescapedchar
EscapedStringis the only structure that is allowed to borrow escaped string data, and uses a special constant to signal to the deserializer that it's special.I believe that this design will also solve #74
An example usage of the new design can be seen at https://github.com/sammhicks/picoserve/tree/json-parse-demo