Claudex.JSONL (Claudex v0.6.1)

Copy Markdown View Source

Splits a JSON Lines byte stream into complete lines — the format the Message Batches API uses for results.

Pure and incremental, like Claudex.Stream.SSE: feed it whatever bytes arrived, get back the lines those bytes completed and a decoder holding the rest. Turning a line into JSON is the caller's job, so a malformed line can be reported with its contents instead of surfacing as a decode error from somewhere deeper.

Summary

Functions

Feeds chunk to the decoder, returning the lines it completed and a decoder holding the partial line at the end. Blank lines are dropped.

Drains the buffer, returning a final line that arrived without a trailing newline.

Builds a decoder with an empty buffer.

Types

t()

@type t() :: %Claudex.JSONL{buffer: binary()}

Functions

decode(jsonl, chunk)

@spec decode(t(), binary()) :: {[binary()], t()}

Feeds chunk to the decoder, returning the lines it completed and a decoder holding the partial line at the end. Blank lines are dropped.

flush(jsonl)

@spec flush(t()) :: {[binary()], t()}

Drains the buffer, returning a final line that arrived without a trailing newline.

new()

@spec new() :: t()

Builds a decoder with an empty buffer.