10 ms·
It is best not to confuse deserialisation and parsing. Parsing is a separate task with separate issues. For JSON deserialisation, Serde is a very convenient AP
by rkangel 7y ago
It is best not to confuse deserialisation and parsing. Parsing is a separate task with separate issues.
For JSON deserialisation, Serde is a very convenient API to use an existing JSON parser that someone else has (hand) written.
If you needed a new syntax, you'd have to write a new parser. I often implement communications protocols as part of my work. In most cases, Serde doesn't help me much there - I have to parse the protocol myself (e.g. using Nom).
- legulere 7y agoWhat is the difference between parsing and deserializing? With both you have a string representation of a data structure that you read and bring into the native form. Do you call it parsing if the grammar is more complicated?
- earthboundkid 7y agoSerde only helps with moving the values from the parser into a struct. It doesn't help with figuring out the data format.
- p0llard 7y agoDeserialisation (in this context) is the act of decoding data from some "string representation" to a representation suitable for use, typically a native format. Typically, although this depends on the specific encoding, a parser is required as one of the first stages of a deserialiser; normally a parser refers to something which applies the rules of something as least as complex as a CFG, as opposed to a lexer/scanner which typically just applies regular expressions; a combination of the two allows the serialised format to be interpreted. You can show quite easily that JSON (and indeed any CFL) cannot be "parsed" using a lexer alone.
- specialist 7y agoGood question, thanks. I had the vague notion that parsing was for human readable content and deserialization was for computer-to-computer content. Now I tentatively make the distinction that compiling transforms streams into code (stream -> lex -> parse -> magic -> code) whereas deserialization is for data. Making parsing just one of the transformation steps for both compilation and deserialization.
- deleted 7y ago[deleted]
- empath75 7y agoSerde includes a bunch of parsers by default but if you invented a new text file format, you’d have to write a new parser for it before you could do anything with it, and serde doesn’t help with that.
- ncmncm 7y agoThe really essential difference is that when you deserialize, you trust the input, and so don't need to check syntax or validity. I.e., you assume it is output of your own serializer, and you can therefore be faster than if you didn't trust it. I have no idea if serde follows this design, or if it has just hijacked the terms.