3 ms·
What are serialization formats, then? What makes them different from notations for data structures?
by parenthephobia 10y ago
What are serialization formats, then? What makes them different from notations for data structures?
- mattnewton 10y agoNot gp, but one difference is you can have a notation that can't capture some state: think of the date class in JavaScript. JSON can't serialize this without resorting to string encoding, whereas something like a protobuf or pickle could.
- steveklabnik 10y agoThat means JSON is missing support for some kinds of data, that doesn't mean that it's not a serialization format at all. Just one with less descriptive power.
- mattnewton 10y agoThat's fair, I guess it's not really a different class but a different shade of the same thing.
- parenthephobia 10y agoWhat's really being described there, I think, is the notion that you can serialize and unserialize some data and get, to some extent, the "same" data back. Whilst that's more possible with protocol buffers or pickling (or whatever your language calls it), I can't think of any languages offhand which can round-trip any data. It's generally not possible to serialize objects denoting external resources - such as open file handles or network sockets. It's also often not possible to serialize closures, weak references (without dereferencing them), and not necessarily possible to serialize self-referencing objects: e.g. a list which contains itself - pickle can handle it, but I don't believe protocol buffers can do it.
- qwertyuiop924 10y agoSome extended sexpr notations (particularly those used in Common Lisp, although many Schemes also support it, as do other lisps) support self-referential data structures. fds and sockets CAN, IIRC, to some degree, be sent to other processes on the same machine, but it's fairly limited. As for serializing closures, CHICKEN Scheme's s11n egg is the most prominent, although not the only, example. It's fairly limited, once again, to avoid sending the forest with the bannana, as Joe Armstrong would put it. This has nothing to do with our discussion, I just thought it was cool.
- qwertyuiop924 10y agoFirst off, make no mistake, JSON and sexprs ARE serialization formats. I didn't establish this well in my orignal comment. However, they're designed be a notation for specific structures: dicts and arrays in json's case, and cons cells, specifically Lisp code in the case of sexprs. This is unlike say, XML, which defines a tree hierarchy, but NOT what the underlying structures are. That's the parser's job.