JsonEventReader structv0.1.0

Source
Reads a document as events, pulling bytes as it needs them.
pub struct JsonEventReader {
    // private fields
}

Associated functions

New

pub func New(
    allocator: Allocator,
    source: Reader,
    limits: JsonLimits
) -> JsonEventReader ! IoError

A reader over source under limits.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
sourceReaderthe text to read
limitsJsonLimitsthe bounds the parse refuses to exceed

Returns: a reader positioned before the first event; Other when its buffer could not be allocated

Source

Methods

Failure

pub func Failure(self: &JsonEventReader) -> JsonParseError?

Why reading stopped, positioned, or none while nothing has gone wrong. This is what a caller asks after Next reports Error. A lexical refusal carries the lexer's own reason inside it rather than in a second call, so a caller holding the failure is holding all of it. The offset counts bytes from the start of the document, however many times the buffer has been refilled. A source that failed is reported as Source, and what it reported is on SourceError.

Returns: the failure, positioned at the byte of the document the reader stopped on, or none

Source

SourceError

pub func SourceError(self: &JsonEventReader) -> IoError?

What the source reported when reading it failed, or none when it has not failed. The end of the stream is not a failure and is never reported here; any other IoError from the source's Read stops the reader, makes Next report Error and Failure report Source, and is kept here unchanged, so a caller can tell a document that is malformed from a stream that broke.

Returns: the source's failure, or none

Source

Text

pub func Text(self: &JsonEventReader) -> char8[..]

The text of the event just reported, valid until the next one. For a name, a string or a number. Escapes are left as written — resolving them would mean allocating, and a caller skipping past a field should not pay for its contents.

Returns: the current event's text, borrowed from the input

Source

TextIsEscaped

pub func TextIsEscaped(self: &JsonEventReader) -> bool

Whether that text holds escapes a caller must resolve.

Returns: whether the text still holds escape sequences a caller must decode

Source

Depth

pub func Depth(self: &JsonEventReader) -> uint

How deeply nested the reader currently is.

Returns: how many arrays and objects are currently open

Source

Release

pub func Release(self: &var JsonEventReader)

Gives the buffer back.

Source

Next

pub func Next(self: &var JsonEventReader) -> JsonEvent

The next event. Separators are consumed silently: a caller sees values and structure, not commas and colons, which is the level a streaming reader is useful at.

Returns: the next event, or the end-of-input event

Source

Destructor

func ~JsonEventReader(self: &var JsonEventReader)

Releases the buffer.

Source

JsonEvent

pub enum JsonEvent: int32 {
    End = 0,
    ObjectStart = 1,
    ObjectEnd = 2,
    ArrayStart = 3,
    ArrayEnd = 4,
    Name = 5,
    Text = 6,
    Number = 7,
    True = 8,
    False = 9,
    Null = 10,
    Error = 11
}

What just happened in the document.

Source

Cases

NameValueDescription
End0The document is finished.
ObjectStart1An object opened.
ObjectEnd2An object closed.
ArrayStart3An array opened.
ArrayEnd4An array closed.
Name5A member name; its text is available until the next event.
Text6A string value; its text is available until the next event.
Number7A number; its text is available until the next event.
True8true.
False9false.
Null10null.
Error11Something went wrong; the reason is on the reader.