The codec compiler: a Descriptor walked once into everything the hot path needs, so that parsing and writing never touch the descriptor API, never resolve a FieldDescriptor, and never ask protobuf-java what an edition feature means — those questions are answered here, per type, the first time the type is used.
A message value is an Object[] of slots, one per field in descriptor order (FieldDescriptor.getIndex), plus an UnknownFieldSet. nil is absent. Fields without presence (proto3 scalars, editions IMPLICIT) are normalized so nil also means the default: readers and setters store nil for the default value, and reads substitute the default back. That keeps the writer's rule one line — write what is non-nil and non-empty — and makes re-encoding bytes that carried an explicit default drop it, as every protobuf implementation does.
Compiled per type:
fields: a CompiledField per slot, with the writer for that field.writers: the same fields in field-number order, the order every
protobuf serializer emits, followed by unknown fields.Nested types compile lazily through the parser-fn the message layer supplies, behind an IDeref, because descriptors are cyclic. One compiler owns one cache, keyed by Descriptor identity.
The codec compiler: a Descriptor walked once into everything the hot path needs, so that parsing and writing never touch the descriptor API, never resolve a FieldDescriptor, and never ask protobuf-java what an edition feature means — those questions are answered here, per type, the first time the type is used. A message value is an Object[] of slots, one per field in descriptor order (FieldDescriptor.getIndex), plus an UnknownFieldSet. nil is absent. Fields without presence (proto3 scalars, editions IMPLICIT) are normalized so nil also means the default: readers and setters store nil for the default value, and reads substitute the default back. That keeps the writer's rule one line — write what is non-nil and non-empty — and makes re-encoding bytes that carried an explicit default drop it, as every protobuf implementation does. Compiled per type: - `fields`: a CompiledField per slot, with the writer for that field. - `writers`: the same fields in field-number order, the order every protobuf serializer emits, followed by unknown fields. - a reader table keyed by TAG, not field number, dense (an array indexed by tag) when the tags allow and binary-searched otherwise. A repeated scalar registers both its packed and its expanded tag, because a parser accepts either encoding whatever the descriptor says it writes. - oneof membership, so reading a member off the wire clears its siblings, and the required slots, for initialization checks. Nested types compile lazily through the parser-fn the message layer supplies, behind an IDeref, because descriptors are cyclic. One compiler owns one cache, keyed by Descriptor identity.
(compiler parser-of)A compile function with its own cache, keyed by Descriptor identity. parser-of takes an IDeref of a CompiledType and returns an IDeref of the Parser that reads that type — the message layer's, or DynamicMessage's in tests. Nested types compile on first use, which is what makes cyclic descriptors terminate.
A compile function with its own cache, keyed by Descriptor identity. parser-of takes an IDeref of a CompiledType and returns an IDeref of the Parser that reads that type — the message layer's, or DynamicMessage's in tests. Nested types compile on first use, which is what makes cyclic descriptors terminate.
(read-into t in slots)Parse in into slots until end of input or an end-group tag, which is
left for the caller (CodedInputStream.readGroup checks it). Returns the
UnknownFieldSet.Builder if anything went unknown, else nil.
Parse `in` into `slots` until end of input or an end-group tag, which is left for the caller (CodedInputStream.readGroup checks it). Returns the UnknownFieldSet.Builder if anything went unknown, else nil.
(size-slots t slots unknown)The serialized size of these slots and unknown fields.
The serialized size of these slots and unknown fields.
(slot-default fd)A scalar field's default in slot representation: protobuf-java's default value, except enums, which are numbers here.
A scalar field's default in slot representation: protobuf-java's default value, except enums, which are numbers here.
(write-slots t slots unknown out)Write present fields in field-number order, then unknown fields.
Write present fields in field-number order, then unknown fields.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |