<oembed><type>rich</type><version>1.0</version><author_name>npub1m230cem2yh3mtdzkg32qhj73uytgkyg5ylxsu083n3tpjnajxx4qqa2np2</author_name><author_url>https://nostr.ae/npub1m230cem2yh3mtdzkg32qhj73uytgkyg5ylxsu083n3tpjnajxx4qqa2np2</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2012-11-28&#xA;📝 Original message:On Mon, Nov 26, 2012 at 05:37:31PM -0500, Gavin Andresen wrote:&#xA;&gt; Why not JSON?&#xA;&gt; -------------&#xA;&gt; &#xA;&gt; Invoice, Payment and Receipt messages could all be JSON-encoded. And&#xA;&gt; the Javascript Object Signing and Encryption (JOSE) working group at&#xA;&gt; the IETF has a draft specification for signing JSON data.&#xA;&gt; &#xA;&gt; But the spec is non-trivial. Signing JSON data is troublesome because&#xA;&gt; JSON can encode the same data in multiple ways (whitespace is&#xA;&gt; insignificant, characters in strings can be represented escaped or&#xA;&gt; un-escaped, etc.), and the standards committee identified at least one&#xA;&gt; security-related issue that will require special JSON parsers for&#xA;&gt; handling JSON-Web-Signed (JWS) data (duplicate keys must be rejected&#xA;&gt; by the parser, which is more strict than the JSON spec requires).&#xA;&gt; &#xA;&gt; A binary message format has none of those complicating issues. Which&#xA;&gt; encoding format to pick is largely a matter of taste, but Protocol&#xA;&gt; Buffers is a simple, robust, multi-programming-language,&#xA;&gt; well-documented, easy-to-work-with, extensible format.&#xA;&#xA;I&#39;m not sure this is actually as much of an advantage as you&#39;d expect. I&#xA;looked into Google Protocol buffers a while back for a timestamping&#xA;project and unfortunately there are many ways in which the actual binary&#xA;encoding of a message can differ even if the meaning of the message is&#xA;the same, just like JSON.&#xA;&#xA;First of all while the order in which fields are encoded *should* be&#xA;written sequentially, parsers are also required to accept the fields in&#xA;any order. There is also a repeated fields feature where the&#xA;fields can either be serialized as one packed key-list pair, or multiple&#xA;key-value(s) pairs; in the latter case the payloads are concatenated.&#xA;&#xA;The general case of how to handle a duplicated field that isn&#39;t supposed&#xA;to be repeated seems to be undefined in the standard. Yet at the same&#xA;time the standard mentions creating messages by concatenating two&#xA;messages together. Presumably parsers treat that case as an error, but I&#xA;wouldn&#39;t be surprised if that isn&#39;t always true.&#xA;&#xA;Implementations differ as well. The current Java and C++ implementations&#xA;write unknown fields in arbitrary order after the sequentially-ordered&#xA;known fields, while on the other hand the Python implementation simply&#xA;drops unknown fields entirely. As far as I know no implementation&#xA;preserves order for unknown fields.&#xA;&#xA;Finally, while not a Protocol Buffers specific problem, UTF8 encoded&#xA;text isn&#39;t guaranteed to survive a UTF8-UTFx-UTF8 round trip.  Multiple&#xA;code point sequences can be semanticly identical so you can expect some&#xA;software to convert one to the other. Similarly lots of languages&#xA;internally store unicode strings by converting to something like UTF16.&#xA;One solution is to use one of the normalization forms such as NFKD - an&#xA;idempotent transformation - although I wouldn&#39;t be surprised if&#xA;normalization itself is complex enough that implementation bugs exist,&#xA;not to mention the fact that the normalization forms have undergone&#xA;different versions.&#xA;&#xA;I think the best way(1) to handle (most) the above by simply treating the&#xA;binary message as immutable and never re-serializing a deserialized&#xA;message, but if you&#39;re willing to do that just using JSON isn&#39;t&#xA;unreasonable either.&#xA;&#xA;&#xA;1) Of course I went off an created Yet Another Binary Serialization for&#xA;my project, but I&#39;m young and foolish...&#xA;&#xA;-- &#xA;&#39;peter&#39;[:-1]@petertodd.org&#xA;-------------- next part --------------&#xA;A non-text attachment was scrubbed...&#xA;Name: signature.asc&#xA;Type: application/pgp-signature&#xA;Size: 490 bytes&#xA;Desc: Digital signature&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20121128/ac1eb23f/attachment.sig&gt;</html></oembed>