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 t

Stream 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 : int

Default batch size.

val create : 
  ?batch_size:int ->
  parser ->
  buffer ->
  len:int ->
  (t, error) result

create ?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_result

next 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 -> int

Return the number of bytes that did not form a full document.

val doc_index : t -> int

Return the current document index.

val is_finished : t -> bool

Return true if the stream is finished.

val size_in_bytes : t -> int

Return the input size in bytes.

val to_seq : t -> (element * int, error * int) result Seq.t

Convert the stream to a sequence.

The int in each Ok/Error value is a byte offset.