@@ -39,17 +39,19 @@ allow for optimization opportunities.
3939## Inherent Barriers to Stable Serialization
4040
4141Protobuf objects preserve unknown fields to provide forward and backward
42- compatibility. Unknown fields cannot be canonically serialized:
43-
44- 1 . Unknown fields can't distinguish between bytes and sub-messages, as both
45- have the same wire type. This makes it impossible to canonicalize messages
46- stored in the unknown field set. If we were going to canonicalize, we would
47- need to recurse into unknown submessages to sort their fields by field
48- number, but we don't have enough information to do this.
49- 1 . Unknown fields are always serialized after known fields, for efficiency. But
50- canonical serialization would require interleaving unknown fields with known
51- fields by field number. This would cause efficiency and code size overheads
52- for everybody, even people who do not use the feature.
42+ compatibility. The handling of unknown fields is a primary obstacle to canonical
43+ serialization.
44+
45+ In the wire format, bytes fields and nested sub-messages use the same wire type.
46+ This ambiguity makes it impossible to correctly canonicalize messages stored in
47+ the unknown field set. Since the exact same contents may be either one, it is
48+ impossible to know whether to treat it as a message and recurse down or not.
49+
50+ For efficiency, implementations typically serialize unknown fields after known
51+ fields. Canonical serialization, however, would require interleaving unknown
52+ fields with known fields according to field number. This would impose
53+ significant efficiency and code size costs on all users, even those not
54+ requiring this feature.
5355
5456## Things Intentionally Left Undefined
5557
@@ -66,4 +68,3 @@ allow for more optimization opportunities:
6668To leave room for optimizations like this, we want to intentionally scramble
6769field order in some configurations, so that applications do not inappropriately
6870depend on field order.
69-
0 commit comments