JsoniterPrism
dev.constructive.eo.jsoniter.JsoniterPrism
object JsoniterPrism
Read-write optic over a JSON byte buffer. Resolves a JSONPath subset against Array[Byte], decodes the focused slice via JsonValueCodec[A] on read, encodes-and-splices on write. No runtime AST.
Carrier: dev.constructive.eo.data.Affine. Shape Optic[Array[Byte], Array[Byte], A, A, Affine]:
type X = (Array[Byte], (Array[Byte], Int, Int))Fst[X] = Array[Byte]— original source bytes (Miss carries this for pass-through)Snd[X] = (Array[Byte], Int, Int)— bytes + the focused span (Hit carries this; phase-2 splice writes use the span to memcpy the new encoding back in)
to: Array[Byte] => Affine[X, A]runs the path scanner; on hit, decodes the slice viareadFromSubArrayand packsHit(snd = (bytes, start, end), b = decoded). On miss (path doesn't resolve, decode throws), packsMiss(fst = bytes)for pass-through.from: Affine[X, A] => Array[Byte](phase 2) — Hit encodesh.bviawriteToArrayand splices into the source bytes at the recorded[start, end)span. Threearraycopys into a fresh buffer; cost is O(src.length). Miss returns the original bytes unchanged.
Composability: the standard cats-eo extension methods on Optic[..., Affine] light up automatically — .foldMap, .modify, .replace, .andThen, etc. No new Composer / AssociativeFunctor needed; reuses the existing Affine machinery.
'''Laws & preconditions''' (normative):
- The Optional laws hold '''up to canonical re-encoding of the focused slice''':
modify(identity)re-encodes the focus through the codec, normalising number forms (1e0→1.0), escapes, and key order INSIDE the span. Bytes outside the span (whitespace, sibling formatting) are never touched. Byte-for-byte identity holds only for focus slices already in the codec's canonical form. - '''Writes require a decodable current focus''': the Affine
todecodes eagerly, so.replaceonto a span whose current value doesn't decode asAis a Miss pass-through — template placeholders must be VALID encodings of the focus type.
Attributes
- Source
- JsoniterPrism.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
JsoniterPrism.type
Members list
In this article