The codec half of the generated-code contract: set-field! and get-field.
Generated ->proto fns call set-field! once per field against a fresh
builder; proto-> fns call get-field once per field feeding the record's
positional constructor. Both take an opts map that is almost always nil.
Semantics the whole design hangs on:
set-field! of nil sets nothing; get-field of an unset
explicit-presence field returns nil. Fields with IMPLICIT presence
(editions) and proto3 no-label scalars have no absence to report, so
get-field returns the value — default included — and never nil.->proto, so recursion happens here, through the handle's
child handles, which carry the concrete-class-correct nested prototypes.opts (all optional): :naming :kebab (default) | :proto — keys used on the generic map path :enums :keyword (default; exact proto value name, e.g. :GREETING_HELLO) | :number | :string — how get-field represents enums; set-field! accepts keyword, string, number or EnumValueDescriptor regardless :bytes :byte-array (default) | :byte-string
The codec half of the generated-code contract: `set-field!` and `get-field`.
Generated `->proto` fns call `set-field!` once per field against a fresh
builder; `proto->` fns call `get-field` once per field feeding the record's
positional constructor. Both take an opts map that is almost always nil.
Semantics the whole design hangs on:
- nil means absent, in both directions. A record has every key; protobuf has
presence. `set-field!` of nil sets nothing; `get-field` of an unset
explicit-presence field returns nil. Fields with IMPLICIT presence
(editions) and proto3 no-label scalars have no absence to report, so
`get-field` returns the value — default included — and never nil.
- Nested message values arrive as records or plain maps; generated code never
calls the nested `->proto`, so recursion happens here, through the handle's
child handles, which carry the concrete-class-correct nested prototypes.
- The proto field name is the authority. Kebab keys are derived; the reverse
mapping does not exist (STYLE_LEGACY).
opts (all optional):
:naming :kebab (default) | :proto — keys used on the generic map path
:enums :keyword (default; exact proto value name, e.g. :GREETING_HELLO)
| :number | :string — how get-field represents enums;
set-field! accepts keyword, string, number or EnumValueDescriptor
regardless
:bytes :byte-array (default) | :byte-string(get-field msg handle)(get-field msg handle opts)Read one field from a message as a Clojure value. nil means absent: an unset explicit-presence field, or an empty repeated/map field. IMPLICIT-presence fields (and proto3 no-label scalars) have no absence and return their value, default included. Nested messages come back as plain maps.
Read one field from a message as a Clojure value. nil means absent: an unset explicit-presence field, or an empty repeated/map field. IMPLICIT-presence fields (and proto3 no-label scalars) have no absence and return their value, default included. Nested messages come back as plain maps.
(set-field! builder handle v)(set-field! builder handle v opts)Set one field on a builder from a Clojure value. nil sets nothing — that is how a record (all keys always present) maps onto protobuf presence. Mutates and returns the builder.
Set one field on a builder from a Clojure value. nil sets nothing — that is how a record (all keys always present) maps onto protobuf presence. Mutates and returns the builder.
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 |