feedInput
Call this whenever you get error.BufferUnderrun from next().
When there is no more input to provide, call endInput().
Function parameters
Parameters
- self:*@This()
- input:[]const u8
The tokens emitted by `std.json.Scanner` and `std.json.Reader` `.next*()` functions follow this grammar:
Types
- Token
- The tokens emitted by `std.json.Scanner` and `std.json.Reader` `.next*()` functions follow this grammar:
- TokenType
- This is only used in `peekNextTokenType()` and gives a categorization based on the first byte of the next token that will be emitted from a `next*()` call.
- Diagnostics
- To enable diagnostics, declare `var diagnostics = Diagnostics{};` then call `source.enableDiagnostics(&diagnostics);`
- AllocWhen
- See the documentation for `std.json.Token`.
- Reader
- All `next*()` methods here handle `error.BufferUnderrun` from `std.json.Scanner`, and then read from the reader.
The allocator is only used to track `[]` and `{}` nesting levels.
Functions
- initStreaming
- The allocator is only used to track `[]` and `{}` nesting levels.
- initCompleteInput
- Use this if your input is a single slice.
- feedInput
- Call this whenever you get `error.BufferUnderrun` from `next()`.
- endInput
- Call this when you will no longer call `feedInput()` anymore.
- nextAlloc
- Equivalent to `nextAllocMax(allocator, when, default_max_value_len);`
- nextAllocMax
- This function is only available after `endInput()` (or `initCompleteInput()`) has been called.
- allocNextIntoArrayList
- Equivalent to `allocNextIntoArrayListMax(value_list, when, default_max_value_len);`
- allocNextIntoArrayListMax
- The next token type must be either `.number` or `.string`.
- skipValue
- This function is only available after `endInput()` (or `initCompleteInput()`) has been called.
- skipUntilStackHeight
- Skip tokens until an `.object_end` or `.array_end` token results in a `stackHeight()` equal the given stack height.
- stackHeight
- The depth of `{}` or `[]` nesting levels at the current position.
- ensureTotalStackCapacity
- Pre allocate memory to hold the given number of nesting levels.
- next
- See `std.json.Token` for documentation of this function.
- peekNextTokenType
- Seeks ahead in the input until the first byte of the next token (or the end of the input)
- validate
- Scan the input and check for malformed JSON.
- isNumberFormattedLikeAnInteger
- For the slice you get from a `Token.number` or `Token.allocated_number`,
Error sets in this namespace
Error Sets
- Error
- The parsing errors are divided into two categories:
Used by `json.reader`.
Values
- default_buffer_size
- Used by `json.reader`.
- default_max_value_len
- For security, the maximum size allocated to store a single string or number value is limited to 4MiB by default.
Source
Implementation
pub fn feedInput(self: *@This(), input: []const u8) void {
assert(self.cursor == self.input.len); // Not done with the last input slice.
if (self.diagnostics) |diag| {
diag.total_bytes_before_current_input += self.input.len;
// This usually goes "negative" to measure how far before the beginning
// of the new buffer the current line started.
diag.line_start_cursor -%= self.cursor;
}
self.input = input;
self.cursor = 0;
self.value_start = 0;
}