JsonEventReader structv0.1.0
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
source | Reader | the text to read |
limits | JsonLimits | the bounds the parse refuses to exceed |
Returns: a reader positioned before the first event; Other when its buffer could not be allocated
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
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
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
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
Depth
pub func Depth(self: &JsonEventReader) -> uint
How deeply nested the reader currently is.
Returns: how many arrays and objects are currently open
Release
pub func Release(self: &var JsonEventReader)
Gives the buffer back.
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
Destructor
func ~JsonEventReader(self: &var JsonEventReader)
Releases the buffer.
Related
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.
Cases
| Name | Value | Description |
|---|---|---|
End | 0 | The document is finished. |
ObjectStart | 1 | An object opened. |
ObjectEnd | 2 | An object closed. |
ArrayStart | 3 | An array opened. |
ArrayEnd | 4 | An array closed. |
Name | 5 | A member name; its text is available until the next event. |
Text | 6 | A string value; its text is available until the next event. |
Number | 7 | A number; its text is available until the next event. |
True | 8 | true. |
False | 9 | false. |
Null | 10 | null. |
Error | 11 | Something went wrong; the reason is on the reader. |