(->kebab-case s)Converts s, assumed to be in snake_case, to kebab-case
Converts `s`, assumed to be in snake_case, to kebab-case
(bytes->proto-map mapper clazz bytes)Deserializes bytes into a proto-map for the given clazz
Deserializes `bytes` into a proto-map for the given `clazz`
(clj-map->proto-map mapper clazz m)Translate a map to a proto-map for the supplied class using mapper m.
The converted map must not violate the class schema, i.e, it must have matching
keyword names as well as value types.
Translate a map to a proto-map for the supplied class using mapper `m`. The converted map must not violate the class schema, i.e, it must have matching keyword names as well as value types.
(defmapper name classes & opts)Define a new proto mapper for the supplied classes using the supplied options.
Supported options:
:key-name-fn - a function that maps a field name, default identity
:enum-value-fn - a function that maps enum values, default identity
:iter-xf - a transducer for key-value map pairs
:encoders - encoders map, {class->{:from-proto fn, :to-proto fn}}
Define a new proto mapper for the supplied classes using the supplied options.
Supported options:
:key-name-fn - a function that maps a field name, default `identity`
:enum-value-fn - a function that maps enum values, default `identity`
:iter-xf - a transducer for key-value map pairs
:encoders - encoders map, `{class->{:from-proto fn, :to-proto fn}}`(dependencies clazz)Return class dependencies for clazz.
Return class dependencies for `clazz`.
(has-field? m k)Returns true iff field k is set in m.
k must be a message type (i.e, non-scalar).
Returns true iff field `k` is set in `m`. `k` must be a message type (i.e, non-scalar).
(hint proto-map clazz mapper)Create a new hint for proto-map for use by p-> calls.
clazz must resolve to the Java protobuf class of the underlying POJO contained within proto-map.
mapper must resolve to a mapper var created via defmapper.
For example:
(p/p-> (p/hint my-map MyClass my-mapper) :field_0 field_1).
This is equivalent to writing (p/p-> my-map :field_0 :field_1), except that the
produced code will be optimized using the hint of the underlying type.
See also: with-hints
Create a new hint for `proto-map` for use by p-> calls. `clazz` must resolve to the Java protobuf class of the underlying POJO contained within `proto-map.` `mapper` must resolve to a mapper var created via `defmapper`. For example: `(p/p-> (p/hint my-map MyClass my-mapper) :field_0 field_1)`. This is equivalent to writing `(p/p-> my-map :field_0 :field_1)`, except that the produced code will be optimized using the hint of the underlying type. See also: `with-hints`
(one-of m k)Returns the value of the field which is set for k,
a one-of type (or nil if none set).
Returns the value of the field which is set for `k`, a one-of type (or `nil` if none set).
(p-> x & forms)Like -> but meant to be used where the initial expression evaluates to a proto-map. Under the hood, p-> will operate on a transient version of the proto-map and persistent! it back when done. Expressions will be pipelined as much as possible (but never reordered) such that (p-> person-proto (assoc-in [:pet :name] "patch") (assoc-in [:pet :kind] :cat)) will only generate a single instance of a pet transient map to which both operations will be applied in succession.
Like `->` but meant to be used where the initial expression evaluates to a proto-map. Under the hood, `p->` will operate on a transient version of the proto-map and `persistent!` it back when done. Expressions will be pipelined as much as possible (but never reordered) such that `(p-> person-proto (assoc-in [:pet :name] "patch") (assoc-in [:pet :kind] :cat))` will only generate a single instance of a pet transient map to which both operations will be applied in succession.
(pcond-> expr & clauses)Equivalent to cond->. See p->
Equivalent to cond->. See `p->`
(proto->proto-map mapper proto)Wraps a new proto-map around proto, a POJO.
Wraps a new proto-map around `proto`, a POJO.
(proto-map mapper clazz & kvs)Returns a new proto-map for the supplied class, via mapper, initialized
to the optionally supplied key-value pairs.
Returns a new proto-map for the supplied class, via `mapper`, initialized to the optionally supplied key-value pairs.
(proto-map->bytes proto-map)Serializes proto-map to protobuf binary
Serializes `proto-map` to protobuf binary
(proto-map->clj-map proto-map)(proto-map->clj-map proto-map xform)Recursively converts a proto-map to a regular Clojure map.
Recursively converts a proto-map to a regular Clojure map.
(proto-map->proto m)Returns the protobuf instance associated with the proto-map
Returns the protobuf instance associated with the proto-map
(remap mapper proto-map)Remaps proto-map using mapper.
The returned proto-map is subject to the configuration of the new mapper.
Remaps `proto-map` using `mapper`. The returned proto-map is subject to the configuration of the new mapper.
(which-one-of m k)Returns a keyword corresponding to which field is set for k,
a one-of type (or nil if none set).
Returns a keyword corresponding to which field is set for `k`, a one-of type (or `nil` if none set).
(with-hints hints & body)Takes a vector of hints (see hint), and introduces a scope within which all hinted variables will be type hinted in p-> calls, then executes & returns the value of body.
For example:
(defn foo [m] (p/with-hints [(p/hint m MyClass my-mapper)] {:height (p/p-> m :height) :name (p/p-> m :name)}))
Since m is hinted in the scope, both p-> calls will use the hint to produce more performant code.
Note that with-hints only applies to p-> calls directly within body, and not recursively. Therefore, the following code will not be hinted:
` (defn get-person-name [person-proto-map] (p/p-> person-proto-map :name))
(with-hints [(p/hint my-map MyClass my-mapper)] (get-person-name my-map )) `
Takes a vector of hints (see `hint`), and introduces a scope within which all hinted variables will be type hinted in `p->` calls, then executes & returns the value of `body.`
For example:
`(defn foo [m]
(p/with-hints [(p/hint m MyClass my-mapper)]
{:height (p/p-> m :height)
:name (p/p-> m :name)}))`
Since `m` is hinted in the scope, both p-> calls will use the hint to produce more performant code.
Note that with-hints only applies to p-> calls directly within `body`, and not recursively. Therefore, the following code will not be hinted:
`
(defn get-person-name [person-proto-map]
(p/p-> person-proto-map :name))
(with-hints
[(p/hint my-map MyClass my-mapper)]
(get-person-name my-map ))
`
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 |