Serialization¶
The canonical wire codec for stable kernel graphs.
serialization
¶
Canonical wire codec for stable QIEC graphs.
The codec is an explicit allowlist, not a generic Python object serializer. Only frozen kernel records, concrete identifier classes, kernel enums, tuples, bytes, and JSON scalars cross the boundary. Runtime attachments, handler callbacks, modules, mappings, and unknown future node tags are rejected.
QIEC_WIRE_FORMAT
module-attribute
¶
The format tag every encoded document carries, checked on decoding.
JsonValue
¶
A JSON document as json.loads returns it and json.dumps accepts it.
SerializationError
¶
Bases: ValueError
A value is not in the stable QIEC wire language.
to_data
¶
to_data(value: object) -> dict[str, JsonValue]
Encode a stable QIEC graph in its versioned wire envelope.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The graph to encode.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, JsonValue]
|
The envelope, carrying the wire format and the ABI alongside the graph. Both are recorded because neither can be guessed from the payload, and a reader that guessed wrong would misread it. |
| RAISES | DESCRIPTION |
|---|---|
SerializationError
|
If the graph contains a value that may not cross the boundary. |
Source code in src/quivers/qiec/serialization.py
from_data
¶
Decode a QIEC graph, rejecting other ABIs and unknown node tags.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The decoded envelope.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
The reconstructed graph. |
| RAISES | DESCRIPTION |
|---|---|
SerializationError
|
If the envelope is malformed, declares another wire format or ABI, or holds a graph that fails to decode. An ABI mismatch is refused rather than attempted, since a payload from another version may use the same tags for different shapes. |
Source code in src/quivers/qiec/serialization.py
dumps
¶
Serialize a QIEC graph as deterministic UTF-8-compatible JSON text.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The graph to serialize.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Compact, key-sorted JSON. Determinism matters because identities downstream are content addressed: the same graph must produce the same bytes on every run and every platform. |
| RAISES | DESCRIPTION |
|---|---|
SerializationError
|
If the graph contains a value that may not cross the boundary. |
Source code in src/quivers/qiec/serialization.py
loads
¶
Deserialize one canonical QIEC JSON document.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The document to read.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
The reconstructed graph. |
| RAISES | DESCRIPTION |
|---|---|
SerializationError
|
If the text is not valid JSON, repeats an object key at any depth, or fails any of the decoding checks. |