# RJiter API Documentation

See `llms-readme.txt` for `RJiter` description.
For Jiter API documentation, see `jiter/llms-all.txt`.

## File: src/lib.rs

### Public Re-exports
```rust
pub use error::Result;
pub use error::Error;
pub use rjiter::RJiter;
pub use jiter;
```

### Modules
- `buffer` - Buffer management for streaming JSON parsing.
- `error` - Error types and handling for `RJiter`.
- `rjiter` - Streaming JSON parser implementation.

## File: src/rjiter.rs

### Structs
#### RJiter
Streaming JSON parser, a wrapper around `Jiter`.
```rust
pub struct RJiter<'rj, R: embedded_io::Read> {
    jiter: Jiter<'rj>,
    buffer: Buffer<'rj, R>,
}
```
**Fields:**
- `jiter: Jiter<'rj>` - The underlying Jiter parser
- `buffer: Buffer<'rj, R>` - Buffer management for streaming

### Functions

#### new
Constructs a new `RJiter`.

# Arguments
- `reader`: The json stream
- `buf`: The working buffer
```rust
pub fn new(reader: &'rj mut R, buf: &'rj mut [u8]) -> Self
where
    R: embedded_io::Read
```

#### peek
See `Jiter::peek`
# Errors
`IoError` or `JiterError`
```rust
pub fn peek(&mut self) -> RJiterResult<Peek>
```

#### known_array
See `Jiter::known_array`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_array(&mut self) -> RJiterResult<Option<Peek>>
```

#### known_bool
See `Jiter::known_bool`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_bool(&mut self, peek: Peek) -> RJiterResult<bool>
```

#### known_bytes
See `Jiter::known_bytes`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_bytes(&mut self) -> RJiterResult<&[u8]>
```

#### known_float
See `Jiter::known_float`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_float(&mut self, peek: Peek) -> RJiterResult<f64>
```

#### known_int
See `Jiter::known_int`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_int(&mut self, peek: Peek) -> RJiterResult<NumberInt>
```

#### known_null
See `Jiter::known_null`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_null(&mut self) -> RJiterResult<()>
```

#### known_number
See `Jiter::known_number`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_number(&mut self, peek: Peek) -> RJiterResult<NumberAny>
```

#### known_object
See `Jiter::known_object`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_object(&mut self) -> RJiterResult<Option<&str>>
```

#### known_skip
See `Jiter::known_skip`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_skip(&mut self, peek: Peek) -> RJiterResult<()>
```

#### known_str
See `Jiter::known_str`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_str(&mut self) -> RJiterResult<&str>
```

#### known_value
See `Jiter::known_value`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_value(&mut self, peek: Peek) -> RJiterResult<JsonValue<'rj>>
```

#### known_value_owned
See `Jiter::known_value_owned`
# Errors
`IoError` or `JiterError`
```rust
pub fn known_value_owned(&mut self, peek: Peek) -> RJiterResult<JsonValue<'static>>
```

#### next_array
See `Jiter::next_array`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_array(&mut self) -> RJiterResult<Option<Peek>>
```

#### array_step
See `Jiter::array_step`
# Errors
`IoError` or `JiterError`
```rust
pub fn array_step(&mut self) -> RJiterResult<Option<Peek>>
```

#### next_bool
See `Jiter::next_bool`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_bool(&mut self) -> RJiterResult<bool>
```

#### next_bytes
See `Jiter::next_bytes`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_bytes(&mut self) -> RJiterResult<&[u8]>
```

#### next_float
See `Jiter::next_float`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_float(&mut self) -> RJiterResult<f64>
```

#### next_int
See `Jiter::next_int`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_int(&mut self) -> RJiterResult<NumberInt>
```

#### next_key
See `Jiter::next_key`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_key(&mut self) -> RJiterResult<Option<&str>>
```

#### next_key_bytes
See `Jiter::next_key_bytes`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_key_bytes(&mut self) -> RJiterResult<Option<&[u8]>>
```

#### next_null
See `Jiter::next_null`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_null(&mut self) -> RJiterResult<()>
```

#### next_number
See `Jiter::next_number`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_number(&mut self) -> RJiterResult<NumberAny>
```

#### next_number_bytes
See `Jiter::next_number_bytes`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_number_bytes(&mut self) -> RJiterResult<&[u8]>
```

#### next_object
See `Jiter::next_object`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_object(&mut self) -> RJiterResult<Option<&str>>
```

#### next_object_bytes
See `Jiter::next_object_bytes`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_object_bytes(&mut self) -> RJiterResult<Option<&[u8]>>
```

#### next_skip
See `Jiter::next_skip`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_skip(&mut self) -> RJiterResult<()>
```

#### next_str
See `Jiter::next_str`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_str(&mut self) -> RJiterResult<&str>
```

#### next_value
See `Jiter::next_value`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_value(&mut self) -> RJiterResult<JsonValue<'rj>>
```

#### next_value_owned
See `Jiter::next_value_owned`
# Errors
`IoError` or `JiterError`
```rust
pub fn next_value_owned(&mut self) -> RJiterResult<JsonValue<'static>>
```

#### finish
See `Jiter::finish`
# Errors
`IoError` or `JiterError`
```rust
pub fn finish(&mut self) -> RJiterResult<()>
```

#### current_index
Get the current index of the parser.
```rust
pub fn current_index(&self) -> usize
```

#### error_position
Get the current `LinePosition` of the parser.
```rust
pub fn error_position(&self, index: usize) -> LinePosition
```

#### write_long_bytes
Write-read-write-read-... until the end of the json string.
The bytes are written as such, without transforming them.
This function is useful to copy a long json string to another json.

Rjiter should be positioned at the beginning of the json string, on a quote character.
Bounding quotes are not included in the output.

# Errors
`IoError` or `JiterError`
```rust
pub fn write_long_bytes<W: embedded_io::Write>(&mut self, writer: &mut W) -> RJiterResult<()>
```

#### write_long_str
Write-read-write-read-... until the end of the json string.
Converts the json escapes to the corresponding characters.

Rjiter should be positioned at the beginning of the json string, on a quote character.
Bounding quotes are not included in the output.

# Errors
`IoError` or `JiterError`
```rust
pub fn write_long_str<W: embedded_io::Write>(&mut self, writer: &mut W) -> RJiterResult<()>
```

#### lookahead_while
Lookahead bytes while a predicate is true, without consuming them.
Returns a slice of the bytes that matched the predicate.

This is a wrapper around `Buffer::collect_while` that returns a slice
instead of an offset. The bytes are not consumed from the buffer.

# Arguments

* `predicate` - A function that returns true if the byte should be accepted

# Errors

Returns `ErrorType::BufferFull` if the buffer fills up with all accepted bytes.
Also returns errors from the underlying reader.
```rust
pub fn lookahead_while<F>(&mut self, predicate: F) -> RJiterResult<&[u8]>
where
    F: Fn(u8) -> bool
```

#### lookahead_n
Lookahead exactly `count` bytes without consuming them.
Returns a slice of the requested bytes, or fewer if EOF is reached.

This is a wrapper around `Buffer::collect_count` that returns a slice
instead of an offset. The bytes are not consumed from the buffer.

# Arguments

* `count` - The number of bytes to lookahead

# Errors

Returns `ErrorType::BufferFull` if the buffer is too small to hold the requested bytes.
Also returns errors from the underlying reader.
```rust
pub fn lookahead_n(&mut self, count: usize) -> RJiterResult<&[u8]>
```

#### skip_n_bytes
Skip exactly `count` bytes, consuming them from the buffer.
Returns the number of bytes actually skipped (may be less than `count` if EOF is reached).

This function skips bytes incrementally, so it works even with small buffers.
It uses `Buffer::skip_n` to find the position, then shifts to consume the bytes.

# Arguments

* `count` - The number of bytes to skip

# Errors

Returns errors from the underlying reader.
```rust
pub fn skip_n_bytes(&mut self, count: usize) -> RJiterResult<usize>
```

#### known_skip_token
Skip the token if found, otherwise return an error.
`RJiter` should be positioned at the beginning of the potential token using `peek()` or `finish()`

# Errors
`IoError` or `RJiterError(ExpectedSomeIdent)`
```rust
pub fn known_skip_token(&mut self, token: &[u8]) -> RJiterResult<()>
```

### Implementations
#### impl RJiter
**Methods:**
All the methods listed above under Functions section.

## File: src/error.rs

### Type Aliases
```rust
pub type Result<T> = core::result::Result<T, Error>;
```

### Structs
#### Error
An error from the `RJiter` iterator.
```rust
pub struct Error {
    pub error_type: ErrorType,
    pub index: usize,
}
```
**Fields:**
- `error_type: ErrorType` - The type of error that occurred
- `index: usize` - The byte index in the input where the error occurred

### Enums
#### ErrorType
Like `Jiter::JiterErrorType`, but also with `IoError`
```rust
pub enum ErrorType {
    JsonError(JsonErrorType),
    WrongType {
        expected: JsonType,
        actual: JsonType,
    },
    IoError {
        kind: embedded_io::ErrorKind,
    },
}
```
**Variants:**
- `JsonError(JsonErrorType)` - JSON parsing error from the underlying jiter
- `WrongType { expected: JsonType, actual: JsonType }` - Type mismatch error
- `IoError { kind: embedded_io::ErrorKind }` - I/O operation error with the specific error kind

### Functions
#### get_position
Get the position of the error in the stream.
```rust
pub fn get_position<R: embedded_io::Read>(&self, rjiter: &RJiter<R>) -> LinePosition
```

#### write_description
Write a description of the error with position information to the provided formatter.
This is more embedded-friendly than returning a String as it doesn't allocate.
Available with `std` or `display` feature.
```rust
#[cfg(any(feature = "std", feature = "display"))]
pub fn write_description<R: embedded_io::Read>(
    &self,
    rjiter: &RJiter<R>,
    f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result
```

#### description
Get the description of the error with position information as a String.
This is only available with std feature as it allocates.
```rust
#[cfg(feature = "std")]
pub fn description<R: embedded_io::Read>(&self, rjiter: &RJiter<R>) -> String
```

### Implementations
#### impl Error
**Methods:**
##### get_position
Get the position of the error in the stream.
```rust
pub fn get_position<R: embedded_io::Read>(&self, rjiter: &RJiter<R>) -> LinePosition
```

## File: src/buffer.rs

### Structs
#### Buffer
A buffer for reading JSON data.
Is a private struct, the "pub" is only for testing.
```rust
pub struct Buffer<'buf, R: embedded_io::Read> {
    reader: &'buf mut R,
    pub buf: &'buf mut [u8],
    pub n_bytes: usize,
    pub n_shifted_out: usize,
    pub pos_shifted: LinePosition,
}
```
**Fields:**
- `reader: &'buf mut R` - The underlying reader
- `buf: &'buf mut [u8]` - The working buffer for reading JSON data
- `n_bytes: usize` - Number of valid bytes in the buffer. Contract: `n_bytes <= buf.len()`
- `n_shifted_out: usize` - Number of bytes that have been shifted out of the buffer
- `pos_shifted: LinePosition` - Line position correction due to shifting operations

### Functions
#### new
Creates a new buffer with the given reader and buffer.
```rust
pub fn new(reader: &'buf mut R, buf: &'buf mut [u8]) -> Self
where
    R: embedded_io::Read
```

#### read_more
Read from the underlying reader into the buffer.

Returns the number of bytes read.

# Errors

From the underlying reader.
```rust
pub fn read_more(&mut self) -> Result<usize, IoError>
```

#### shift_buffer
Shift the buffer to the left, and update the index and line-column position.

# Arguments

* `to_pos`: The position to shift to. Usually is 0 or is 1 for strings.
* `from_pos`: The position to shift from. The case of outside the buffer is handled.
```rust
pub fn shift_buffer(&mut self, to_pos: usize, from_pos: usize)
```

#### skip_spaces
Skip over any ASCII whitespace characters starting at the given position.
Read-shift-read-shift-read-shift... until non-whitespace is found or EOF is reached.

# Arguments

* `pos` - The position in the buffer to start skipping from

# Errors

From the underlying reader.
```rust
pub fn skip_spaces(&mut self, pos: usize) -> Result<(), IoError>
```

### Implementations
#### impl Buffer
**Methods:**
##### new
Creates a new buffer with the given reader and buffer.
```rust
pub fn new(reader: &'buf mut dyn Read, buf: &'buf mut [u8]) -> Self
```
