Expand description
JSON as CPython 3.11’s json.dumps(value, indent=2) writes it at its
other defaults (docs/plans/extract.md E24): ensure_ascii, so every
character outside ' '..='~' is a \uXXXX escape (lowercase hex, a
character past U+FFFF as its surrogate pair) but \b, \f, \n, \r
and \t, which have short forms, as " and \ do; allow_nan, so a
NaN is NaN and the infinities Infinity and -Infinity; a float as
its repr; the separators , and : that indent implies; an empty
list [] and an empty object {}, each on its line.
A value is a typetree value as UnityPy 1.25.2’s read_typetree() gives
it (unityrs_core::Value): a dict as an object in its field order, a
pair or any list as an array, an f32 widened exactly to the double, a
string decoded from its bytes as Python’s surrogateescape decodes them
(each byte of an invalid UTF-8 sequence becomes the lone surrogate
U+DC00 + byte, written \udcXX). Bytes (TypelessData) are a value
json.dumps cannot write (Unwritable).
Options::MONO_BEHAVIOUR selects four spaces and ensure_ascii=False.
In this mode valid non-ASCII characters remain UTF-8 (including DEL and
U+2028); escaped source bytes are written back verbatim, modeling the
final UTF-8 surrogateescape encoding. Only U+DC80..U+DCFF can arise from
a raw byte string; Python’s encoder would raise on other lone surrogates,
which this value model cannot represent.
Every write goes through a Sink: Count measures a document
before anything is allocated for it, so the caller charges the exact
size first, then writes into a buffer of that capacity. The value walk
keeps an explicit stack, one frame per open container, charged to the
caller’s meter before it grows, so no value’s depth costs the thread’s
stack.
Structs§
- Count
- A
Sinkthat only counts. - Options
- JSON formatting;
MONO_BEHAVIOURincludes the extractor’s final UTF-8surrogateescapeencoding, so malformed source bytes round-trip. - Unwritable
- A value
json.dumpsraises on: bytes (TypelessData), which E25 makes the atlas JSON’s skip,json_unwritable.
Enums§
- Write
Error - Why a value was not written: a value
json.dumpscannot write, or the refused charge of the walk’s stack.
Traits§
- Sink
- Where the writer puts its bytes.
Functions§
- decode_
escaped bytesdecoded as Python’ssurrogateescapedecodes them: each valid UTF-8 character as itself (Ok), each byte of an invalid sequence as one item of its own (Err(byte)), in order.- float
- Python’s
reprof a double, asjson.dumpswrites a float. - float_
repr - Python’s
repr(x)for a float asjson.dumpswrites it: the core’spy_float_repr(the nearest of the shortest digits that read back, ties to even), but JSON’sNaN,Infinityand-Infinity. - int
- A decimal integer.
- newline
- A newline and
levellevels of two spaces. - string
- A JSON string of
bytes, decoded asdecode_escapeddecodes them and escaped asensure_asciiescapes (module docs). - value
- Writes
value, read withparsed’s node lists (which name a dict’s keys), as it sits atlevellevels of indentation: its first line continues the current one, its nested lines are indented below it. The walk’s stack, a frame per open container, is charged tometerbefore it grows (review round 2’s S3), and returned when the write ends. - value_
with valuewith explicit formatting and final UTF-8 surrogateescape encoding.