Simdjsont.Raw.Stream
simdjsont · API reference
Parse multiple JSON documents from a buffer.
Streams handle newline-delimited JSON and concatenated JSON documents. They keep byte offsets so callers can report where each document or parse error occurred. A malformed document terminates the stream: after an Error, no later documents are produced.
type tStream state.
type next_result =
| End
| Doc of {
element : element;
byte_offset : int;
}
| Error of {
error : error;
byte_offset : int;
} (* Result of next.byte_offset is an offset into the stream input. *)val default_batch_size : intDefault batch size.
val create :
?batch_size:int ->
parser ->
buffer ->
len:int ->
(t, error) resultcreate ?batch_size parser buf ~len creates a stream over the first len bytes of buf. batch_size controls simdjson's internal parse-many batch size; the default is suitable for most inputs.
val next : t -> next_resultnext stream returns the next document, an error with its byte offset, or End. Returned elements alias parser-owned storage and are valid until the owning parser is reused.
val truncated_bytes : t -> intReturn the number of bytes that did not form a full document.
val doc_index : t -> intReturn the current document index.
val is_finished : t -> boolReturn true if the stream is finished.
val size_in_bytes : t -> intReturn the input size in bytes.
val to_seq : t -> (element * int, error * int) result Seq.tConvert the stream to a sequence.
The int in each Ok/Error value is a byte offset.