The runtime half of protoc-gen-clojure's generated-code contract.
Generated files call exactly four things here: file-descriptor to rebuild
their embedded FileDescriptorProto, known-file for well-known-type deps,
message for a prototype per message, and field for a handle per field.
Everything protobuf decides per edition — presence, delimited encoding, utf8
validation, packedness — is resolved by protobuf-java when the descriptor is
built, which is why generated code never mentions editions at all.
field returns a precomputed FieldHandle rather than a bare FieldDescriptor:
the codec's hot path dispatches on a keyword and never touches the descriptor
API per call. Handles are built against a specific prototype, so a
message-typed field's nested prototype has the right concrete class in both
the DynamicMessage and generated-class arms.
The runtime half of protoc-gen-clojure's generated-code contract. Generated files call exactly four things here: `file-descriptor` to rebuild their embedded FileDescriptorProto, `known-file` for well-known-type deps, `message` for a prototype per message, and `field` for a handle per field. Everything protobuf decides per edition — presence, delimited encoding, utf8 validation, packedness — is resolved by protobuf-java when the descriptor is built, which is why generated code never mentions editions at all. `field` returns a precomputed FieldHandle rather than a bare FieldDescriptor: the codec's hot path dispatches on a keyword and never touches the descriptor API per call. Handles are built against a specific prototype, so a message-typed field's nested prototype has the right concrete class in both the DynamicMessage and generated-class arms.
(field prototype field-name)A precomputed handle for one field of a message prototype, looked up by its exact proto field name — the name is the authority; kebab-cased keys are derived from it, never the reverse (STYLE_LEGACY files can mix conventions).
A precomputed handle for one field of a message prototype, looked up by its exact proto field name — the name is the authority; kebab-cased keys are derived from it, never the reverse (STYLE_LEGACY files can mix conventions).
(file-descriptor descriptor-b64 deps)Build a FileDescriptor from the base64 FileDescriptorProto a generated file
embeds, linked against its dependencies (already-built FileDescriptors —
sibling namespaces' file-descriptor vars or known-file results).
Build a FileDescriptor from the base64 FileDescriptorProto a generated file embeds, linked against its dependencies (already-built FileDescriptors — sibling namespaces' `file-descriptor` vars or `known-file` results).
(known-file path)The FileDescriptor for a well-known type bundled in protobuf-java, e.g. "google/protobuf/timestamp.proto".
The FileDescriptor for a well-known type bundled in protobuf-java, e.g. "google/protobuf/timestamp.proto".
(message fd lookup)(message fd lookup class-hint)The prototype for a message type: a default instance whose
.newBuilderForType the generated ->proto fns drive.
With a Java class hint (3-arity) the generated class's default instance is used when it is present and describes the same message — measured ~45% faster to encode and ~46% lighter on allocation than DynamicMessage for small messages. Otherwise, and always in the 2-arity, a DynamicMessage prototype. Same codec, same field descriptors, same bytes either way.
The prototype for a message type: a default instance whose `.newBuilderForType` the generated `->proto` fns drive. With a Java class hint (3-arity) the generated class's default instance is used when it is present and describes the same message — measured ~45% faster to encode and ~46% lighter on allocation than DynamicMessage for small messages. Otherwise, and always in the 2-arity, a DynamicMessage prototype. Same codec, same field descriptors, same bytes either way.
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 |