Streaming decoder for TOON format.
Provides memory-efficient event-based decoding for large TOON documents. Instead of building complete value trees, emits parse events that can be consumed incrementally.
Streaming decoder for TOON format. Provides memory-efficient event-based decoding for large TOON documents. Instead of building complete value trees, emits parse events that can be consumed incrementally.
(decode-stream source)(decode-stream source options)Decode TOON lines asynchronously into core.async channel of events.
Processes TOON content from either a string, lazy sequence, or async channel, emitting parse events to an output channel.
Parameters:
Returns: core.async channel of events (same format as decode-stream-sync)
Example: (let [lines ["name: Alice" "age: 30"] events-ch (decode-stream lines)] (async/<!! (async/into [] events-ch))) => [{:type :start-object} {:type :key :key "name"} {:type :primitive :value "Alice"} {:type :key :key "age"} {:type :primitive :value 30} {:type :end-object}]
Example with async source: (let [source-ch (async/to-chan! ["name: Alice" "age: 30"]) events-ch (decode-stream source-ch)] (async/<!! (async/into [] events-ch)))
Decode TOON lines asynchronously into core.async channel of events.
Processes TOON content from either a string, lazy sequence, or async channel,
emitting parse events to an output channel.
Parameters:
- source: Either:
- String in TOON format
- Sequence of strings (TOON lines)
- core.async channel of strings
- options: Optional map with keys:
- :indent - Number of spaces per indentation level (default: 2)
- :strict - Enable strict validation (default: true)
- :buf-size - Channel buffer size (default: 32)
Returns:
core.async channel of events (same format as decode-stream-sync)
Example:
(let [lines ["name: Alice" "age: 30"]
events-ch (decode-stream lines)]
(async/<!! (async/into [] events-ch)))
=> [{:type :start-object}
{:type :key :key "name"}
{:type :primitive :value "Alice"}
{:type :key :key "age"}
{:type :primitive :value 30}
{:type :end-object}]
Example with async source:
(let [source-ch (async/to-chan! ["name: Alice" "age: 30"])
events-ch (decode-stream source-ch)]
(async/<!! (async/into [] events-ch)))(decode-stream-sync lines)(decode-stream-sync lines options)Decode TOON lines into lazy sequence of parse events.
Processes TOON content line-by-line, emitting parse events instead of building complete value trees. Memory-efficient for large documents.
Parameters:
Returns: Lazy sequence of events. Event types: {:type :start-object} {:type :end-object} {:type :start-array :length n} {:type :end-array} {:type :key :key "field-name"} ; :was-quoted true when quoted {:type :primitive :value <value>}
Example: (decode-stream-sync "name: Alice\nage: 30") => ({:type :start-object} {:type :key :key "name"} {:type :primitive :value "Alice"} {:type :key :key "age"} {:type :primitive :value 30} {:type :end-object})
Decode TOON lines into lazy sequence of parse events.
Processes TOON content line-by-line, emitting parse events instead of
building complete value trees. Memory-efficient for large documents.
Parameters:
- lines: String or sequence of TOON lines (strings)
- options: Optional map with keys:
- :indent - Number of spaces per indentation level (default: 2)
- :strict - Enable strict validation (default: true)
Returns:
Lazy sequence of events. Event types:
{:type :start-object}
{:type :end-object}
{:type :start-array :length n}
{:type :end-array}
{:type :key :key "field-name"} ; :was-quoted true when quoted
{:type :primitive :value <value>}
Example:
(decode-stream-sync "name: Alice\nage: 30")
=> ({:type :start-object}
{:type :key :key "name"}
{:type :primitive :value "Alice"}
{:type :key :key "age"}
{:type :primitive :value 30}
{:type :end-object})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 |