News for hackers. Stuff that matters.
Re:Understanding Serde by rkangel on Monday November 18, 2019 @05:41AM (#21563254)
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).

Re:Understanding Serde by legulere on Monday November 18, 2019 @08:21AM (#21564051)
What 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?
Re:Understanding Serde by p0llard on Monday November 18, 2019 @08:42AM (#21564204)
Deserialisation (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.

Re:Understanding Serde by empath75 on Monday November 18, 2019 @11:14AM (#21565422)
Serde 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.
Re:Understanding Serde by specialist on Monday November 18, 2019 @09:28AM (#21564524)
Good 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.

Re:Understanding Serde by earthboundkid on Monday November 18, 2019 @08:37AM (#21564175)
Serde only helps with moving the values from the parser into a struct. It doesn't help with figuring out the data format.
Re:Understanding Serde by ncmncm on Monday November 18, 2019 @02:33PM (#21567377)
The 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.