Liking cljdoc? Tell your friends :D

nats-cljc.codec

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`).
raw docstring

bytes->strclj/s

(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`.
sourceraw docstring

decodeclj/s

(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`.
sourceraw docstring

encodeclj/s

(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`.
sourceraw docstring

ICodecclj/sprotocol

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.

-decodeclj/s

(-decode codec bytes)

Decode wire bytes to a Clojure value.

Decode wire bytes to a Clojure value.

-encodeclj/s

(-encode codec value)

Encode a Clojure value to wire bytes.

Encode a Clojure value to wire bytes.
sourceraw docstring

register!clj/s

(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.
sourceraw docstring

str->bytesclj/s

(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.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close