Private low-level utils for reading/writing data, don't use.
Private low-level utils for reading/writing data, don't use.
(bb->din bb)Returns a DataInput adapter over given ByteBuffer.
Reads from the buffer's current position and advances it.
Returns a `DataInput` adapter over given `ByteBuffer`. Reads from the buffer's current position and advances it.
(bb->dout bb)Returns a DataOutput adapter over given ByteBuffer.
Writes at the buffer's current position and advances it.
Returns a `DataOutput` adapter over given `ByteBuffer`. Writes at the buffer's current position and advances it.
(bb-big-endian! bb)(fast-writers?)Returns true iff write-el's fast paths match the effective protocol
writers. extend installs a new protocol map, so the usual case needs
only an identity check. Called once per collection.
Returns true iff `write-el`'s fast paths match the effective protocol writers. `extend` installs a new protocol map, so the usual case needs only an identity check. Called once per collection.
(write-typed _ bb dout_)Writes given object as type-prefixed bytes. Excludes IObj meta.
Writes given object as type-prefixed bytes. Excludes IObj meta.
(write-typed-din _ dout)Writes given object as type-prefixed bytes. Excludes IObj meta. Takes legacy DataInput, used for custom extensions.
Writes given object as type-prefixed bytes. Excludes IObj meta. Takes legacy `DataInput`, used for custom extensions.
(write-typed-meta _ bb dout_)Writes given IObj as type-prefixed bytes. Includes metadata.
Writes given IObj as type-prefixed bytes. Includes metadata.
(read-biginteger ibr)(read-bytes ibr)(read-bytes ibr len)(read-bytes-lg ibr)(read-bytes-md ibr)(read-bytes-sm ibr)(read-bytes-sm* ibr)(read-custom ibr prefixed? type-id)(read-deftype ibr class-name legacy?)(read-into to ibr n)(read-kvs-depr to ibr)(read-kvs-into to ibr n)(read-kw ibr len)Reads a keyword of len UTF-8 bytes.
Reads a keyword of `len` UTF-8 bytes.
(read-lg-count ibr)(read-list ibr n bounded-count?)Reads n type-prefixed elements as a PersistentList.
bounded-count? should be true iff n came from a sm/md (byte/short)
prefix, so is inherently too small to enable an allocation attack. Only
then may we pre-size an array without first checking readable length.
Reads `n` type-prefixed elements as a `PersistentList`. `bounded-count?` should be true iff `n` came from a sm/md (byte/short) prefix, so is inherently too small to enable an allocation attack. Only then may we pre-size an array without first checking readable length.
(read-map ibr n)(read-md-count ibr)(read-quarantined-serializable-object-unsafe! m)Given a quarantined Serializable object like
{:nippy/unthawable {:class-name <> :content <quarantined-ba>}}, reads and
returns the object WITHOUT regard for *thaw-serializable-allowlist*.
MAY BE UNSAFE! Don't call this unless you absolutely trust the payload to not contain any malicious code.
See *thaw-serializable-allowlist* for more info.
Given a quarantined Serializable object like
{:nippy/unthawable {:class-name <> :content <quarantined-ba>}}, reads and
returns the object WITHOUT regard for `*thaw-serializable-allowlist*`.
**MAY BE UNSAFE!** Don't call this unless you absolutely trust the payload
to not contain any malicious code.
See `*thaw-serializable-allowlist*` for more info.(read-record ibr class-name)(read-sm-count ibr)(read-sm-ucount ibr)(read-str ibr)(read-str ibr len)(read-str-lg ibr)(read-str-md ibr)(read-str-sm ibr)(read-str-sm* ibr)(read-sz ibr class-name legacy?)(read-sz!! input-stream class-name)Reads object using Java Serializable. May be unsafe!
Reads object using Java `Serializable`. May be unsafe!
(read-typed ibr)Reads one object as type-prefixed bytes from given IByteReader.
Reads one object as type-prefixed bytes from given `IByteReader`.
(read-vec ibr n)(stream-kind _)Returns this native writer's ?streaming strategy. Registered in parallel
with IWriteTypedNoMeta so both use identical protocol dispatch.
Returns this native writer's ?streaming strategy. Registered in parallel with `IWriteTypedNoMeta` so both use identical protocol dispatch.
(with-bb f)(with-bb init-size f)(with-bb init-size f finalize)(with-bb bb state mark f)(with-bb bb state mark f finalize)Executes (f bb dout_) and returns ?ba of bb when f returns truthy.
bb ---- Auto-expanding ByteBuffer. Will reuse ThreadLocal when possible,
retaining up to 1 MiB per thread for reuse.
dout_ - Call (dout_) to get a DataOutput view on bb.
finalize is called on the final (settled) bb to produce the return
value, and defaults to copying bb's written bytes to a new ba. Callers
that only need to consume the bytes (e.g. write them to a DataOutput)
can pass a custom finalize to avoid that copy.
Executes `(f bb dout_)` and returns ?ba of bb when `f` returns truthy.
`bb` ---- Auto-expanding `ByteBuffer`. Will reuse ThreadLocal when possible,
retaining up to 1 MiB per thread for reuse.
`dout_` - Call (dout_) to get a `DataOutput` view on `bb`.
`finalize` is called on the final (settled) `bb` to produce the return
value, and defaults to copying `bb`'s written bytes to a new ba. Callers
that only need to consume the bytes (e.g. write them to a `DataOutput`)
can pass a custom `finalize` to avoid that copy.(write-auto-cached-kw bb kw state)Like write-cached-kw but starts caching only on a kw's SECOND
occurrence per session (1st occurrence written plain), so that kws
that never repeat don't pay any caching cost in the output.
Like `write-cached-kw` but starts caching only on a kw's SECOND occurrence per session (1st occurrence written plain), so that kws that never repeat don't pay any caching cost in the output.
(write-biginteger bb n)(write-bytes bb ba)(write-bytes-lg bb ba)(write-bytes-md bb ba)(write-bytes-sm bb ba)(write-bytes-sm* bb ba)(write-cached bb dout_ x-val state)(write-cached-header! bb x-val state)Registers x-val in the cache and writes its cache ref id.
Returns true iff x-val itself must still be written after the id.
Shared by the buffered and streaming writers, so both agree on both the
emitted bytes and the cache idxs they imply. NB the cache mutation happens
here, alongside the id write, so a caller that discards the written bytes
(see stream-leaf!) can undo both together.
Registers `x-val` in the cache and writes its cache ref id. Returns true iff `x-val` itself must still be written after the id. Shared by the buffered and streaming writers, so both agree on both the emitted bytes and the cache idxs they imply. NB the cache mutation happens here, alongside the id write, so a caller that discards the written bytes (see `stream-leaf!`) can undo both together.
(write-cached-kw bb kw state)Like write-cached but specialized for cached keywords:
uses bare kw cache keys (kws can't have meta, can't .equals the
[<val> <meta>] keys used for manually cached vals), and writes kws
directly (avoiding re-dispatch through the Keyword writer).
Like `write-cached` but specialized for cached keywords: uses bare kw cache keys (kws can't have meta, can't `.equals` the `[<val> <meta>]` keys used for manually cached vals), and writes kws directly (avoiding re-dispatch through the `Keyword` writer).
(write-cached-ref bb idx)Writes cache ref id (+ idx payload when idx > 7) for given idx <= 32767.
Writes cache ref id (+ idx payload when idx > 7) for given idx <= 32767.
(write-coll bb dout_ id-lg coll)(write-coll bb dout_ id-empty id-sm id-md id-lg coll)(write-coll-header bb id-0 id-sm id-md id-lg cnt)Writes coll id + count.
Writes coll id + count.
(write-coll-header* bb id-0 id-sm* id-sm_ id-md id-lg cnt)Writes coll id + count, packing sm counts as unsigned when enabled.
Writes coll id + count, packing sm counts as unsigned when enabled.
(write-counted-coll bb dout_ id-lg coll)(write-counted-coll bb dout_ id-empty id-sm id-md id-lg coll)(write-double bb n)(write-dyn-array-lg bb dout_ arr alen id)Writes an array of dynamic (individually type-prefixed) elements.
Writes an array of dynamic (individually type-prefixed) elements.
(write-id bb id)(write-kvs bb dout_ id-lg coll)(write-kvs bb dout_ id-empty id-sm id-md id-lg coll)(write-kw bb kw)(write-kw* bb kw state)Writes given keyword, auto-caching it in the given (current) session.
Takes state so that callers writing many keywords
can read tl:cache once rather than once per keyword.
Writes given keyword, auto-caching it in the given (current) session. Takes `state` so that callers writing many keywords can read `tl:cache` once rather than once per keyword.
(write-lg-count bb n)(write-long bb n)(write-long-legacy bb n)(write-map bb dout_ m is-metadata?)Micro-optimized write-kvs w/ id-map-0 id-map-sm id-map-md id-map-lg.
Micro-optimized `write-kvs` w/ id-map-0 id-map-sm id-map-md id-map-lg.
(write-md-count bb n)(write-readable bb x)(write-set bb dout_ s)Micro-optimized write-counted-coll w/ id-set-0 id-set-sm id-set-md id-set-lg.
Micro-optimized `write-counted-coll` w/ id-set-0 id-set-sm id-set-md id-set-lg.
(write-sm-count bb n)(write-sm-ucount bb n)(write-str bb s)(write-str-lg bb s)(write-str-md bb s)(write-str-sm bb s)(write-str-sm* bb s)(write-sym bb sym)(write-sz bb x)Writes given arg using Java Serializable.
Returns true iff allowed.
Writes given arg using Java `Serializable`. Returns true iff allowed.
(write-typed+meta x bb dout_)(write-typed+meta* x bb dout_ incl-meta?)Like write-typed+meta, but takes a pre-read *incl-metadata?*.
Like `write-typed+meta`, but takes a pre-read `*incl-metadata?*`.
(write-typed+meta-to-out! dout x)Streams given object to given DataOutput, holding only a small chunk of
its serialized bytes in memory at a time.
Counted colls and cached values stream at every nesting depth, so their
total serialized size is unbounded. Individual values are still buffered in
full, so each is capped at ~2 GiB: strings, byte arrays, uncounted/lazy
seqs, records, deftypes, custom (extend-freeze) types, and metadata maps.
NB writes are NOT atomic: on error dout may have received partial bytes.
A shared with-cache session's cache IS restored though, so a failed write
that flushed nothing (the usual case, since a chunk holds 64 KiB) leaves the
session fully intact.
Streams given object to given `DataOutput`, holding only a small chunk of its serialized bytes in memory at a time. Counted colls and `cache`d values stream at every nesting depth, so their total serialized size is unbounded. Individual values are still buffered in full, so each is capped at ~2 GiB: strings, byte arrays, uncounted/lazy seqs, records, deftypes, custom (`extend-freeze`) types, and metadata maps. NB writes are NOT atomic: on error `dout` may have received partial bytes. A shared `with-cache` session's cache IS restored though, so a failed write that flushed nothing (the usual case, since a chunk holds 64 KiB) leaves the session fully intact.
(write-uncounted-coll bb dout_ id-lg coll)(write-uncounted-coll bb dout_ id-empty id-sm id-md id-lg coll)(write-vec bb dout_ v)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 |