Codecs convert between Clojure values and the bytes on the wire (ADR 0004).
A codec is an ICodec — -encode/-decode. The dependency-free built-ins
(:edn the default, :string, :bytes) are records held in a defonce
registry keyed by keyword; opt-in codecs (:transit/:json) self-register
from their own namespace via register!, so (require …) is what makes their
keyword resolvable (ADR 0011). A custom codec is any ICodec instance and is
accepted wherever a keyword is.
encode/decode are the public seam core calls: they resolve-codec the
reference (instance as-is, keyword via the registry) and call the protocol
method. :edn decodes with clojure.edn / cljs.reader (never eval).
Codecs convert between Clojure values and the bytes on the wire (ADR 0004). A codec is an `ICodec` — `-encode`/`-decode`. The dependency-free built-ins (`:edn` the default, `:string`, `:bytes`) are records held in a `defonce` registry keyed by keyword; opt-in codecs (`:transit`/`:json`) self-register from their own namespace via `register!`, so `(require …)` is what makes their keyword resolvable (ADR 0011). A custom codec is any `ICodec` instance and is accepted wherever a keyword is. `encode`/`decode` are the public seam `core` calls: they `resolve-codec` the reference (instance as-is, keyword via the registry) and call the protocol method. `:edn` decodes with clojure.edn / cljs.reader (never `eval`).
(bytes->str b)UTF-8-decode wire bytes b to a string — the inverse of str->bytes.
UTF-8-decode wire bytes `b` to a string — the inverse of `str->bytes`.
(decode codec bytes)Decode wire bytes to a Clojure value using codec (a keyword or ICodec).
Any failure surfaces as ex-info :type :codec-error.
Decode wire bytes to a Clojure value using `codec` (a keyword or `ICodec`). Any failure surfaces as `ex-info` `:type :codec-error`.
(encode codec value)Encode a Clojure value to wire bytes using codec (a keyword or ICodec).
Any failure surfaces as ex-info :type :codec-error.
Encode a Clojure value to wire bytes using `codec` (a keyword or `ICodec`). Any failure surfaces as `ex-info` `:type :codec-error`.
The codec extension point (ADR 0011): a pair of pure conversions between a Clojure value and wire bytes. Public — the moment a consumer ships a custom codec, these method names are API.
The codec extension point (ADR 0011): a pair of pure conversions between a Clojure value and wire bytes. Public — the moment a consumer ships a custom codec, these method names are API.
(-decode codec bytes)Decode wire bytes to a Clojure value.
Decode wire bytes to a Clojure value.
(-encode codec value)Encode a Clojure value to wire bytes.
Encode a Clojure value to wire bytes.
(register! k codec)Register codec (an ICodec) under keyword k. The built-ins register
themselves below; opt-in codec namespaces call this at load time, so requiring
the namespace is what makes k resolvable.
Register `codec` (an `ICodec`) under keyword `k`. The built-ins register themselves below; opt-in codec namespaces call this at load time, so requiring the namespace is what makes `k` resolvable.
(str->bytes s)UTF-8-encode string s to wire bytes. The single UTF-8 bridge the built-in
codecs and the opt-in :json/:transit namespaces share; public so a custom
ICodec can produce honest wire bytes too.
UTF-8-encode string `s` to wire bytes. The single UTF-8 bridge the built-in codecs and the opt-in `:json`/`:transit` namespaces share; public so a custom `ICodec` can produce honest wire bytes too.
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 |