Skip to main content

JcsDecoder

Struct JcsDecoder 

Source
pub struct JcsDecoder<'budget, R = JsonResource, Q = usize>{ /* private fields */ }
Expand description

Decodes strict JSON text into an owned value using finite binary64 numbers. Construction uses the shared builder and the configured, root-inclusive max_depth; there is no additional fixed container limit. The legacy methods return a bare serde_json::Value; callers accepting deep documents should use the decode_value_* methods to retain iterative cleanup. The decoder borrows its accounting session for 'budget; R selects the resource kind and Q is the quantity representation used by that session. Calls reuse the same cumulative session, so limits apply across all inputs decoded through this value.

§Type Parameters

  • R is the resource kind tracked by the session.
  • Q is the quantity type used to represent resource limits and usage.

§Examples

use qubit_json::decode::JcsDecoder;

let value = JcsDecoder::unlimited().decode_str("1.5").unwrap();
assert_eq!(value.as_f64(), Some(1.5));

Implementations§

Source§

impl<R, Q> JcsDecoder<'static, R, Q>
where R: Clone, Q: ResourceQuantity,

Source

pub fn with_limits(limits: JsonDecodeLimits<R, Q>) -> Self

Creates a decoder with the supplied cumulative resource limits.

The limits are moved into a new accounting session and remain shared by every decode performed through the returned decoder.

§Parameters
  • limits contains the resource ceilings for this decoder’s session.
§Returns

A decoder that owns a session initialized from limits.

Source§

impl JcsDecoder<'static, JsonResource, usize>

Source

pub fn unlimited() -> Self

Creates a decoder with no configured resource limits.

Resource ceilings are not configured, so resource usage is not limited by this session. Syntax, numeric, and duplicate-key checks still apply; the shared builder has no separate fixed depth cap.

§Returns

A decoder backed by a fresh unlimited accounting session.

Source§

impl<'budget, R, Q> JcsDecoder<'budget, R, Q>
where R: Clone, Q: ResourceQuantity,

Source

pub const fn new(session: JsonDecodeSession<'budget, R, Q>) -> Self

Creates a decoder around a reusable accounting session.

The session is moved into the decoder and borrowed for 'budget; its cumulative usage and configured limits are retained across decode calls.

§Parameters
  • session is the accounting state to use for subsequent decodes.
§Returns

A decoder using the supplied session and redacted diagnostics.

Source

pub const fn with_diagnostic_policy(self, policy: DiagnosticPolicy) -> Self

Selects how much input-derived error detail is retained.

Detailed diagnostics may retain input text and parser sources; use them only when those values are safe to expose. This setting affects errors from later decode calls.

§Parameters
  • policy determines whether decode errors redact input-derived data.
§Returns

This decoder with the selected diagnostic policy.

Source

pub const fn diagnostic_policy(&self) -> DiagnosticPolicy

Returns the active diagnostic policy.

§Returns

The policy applied to errors from subsequent decode calls.

Source

pub const fn session(&self) -> &JsonDecodeSession<'budget, R, Q>

Returns the cumulative accounting session.

The borrow is tied to this decoder and permits inspecting limits and usage without transferring ownership of the session.

§Returns

A shared reference to the session used by this decoder.

Source

pub const fn session_mut(&mut self) -> &mut JsonDecodeSession<'budget, R, Q>

Returns mutable access to the cumulative accounting session.

The borrow is tied to this decoder and allows callers to inspect or adjust session accounting before another decode.

§Returns

A mutable reference to the session used by this decoder.

Source

pub fn into_session(self) -> JsonDecodeSession<'budget, R, Q>

Consumes this decoder and returns its accounting session.

This transfers the accumulated resource state to the caller so it can be inspected or reused by another decoder.

§Returns

The session previously owned by this decoder.

Source

pub fn decode_str(&mut self, input: &str) -> Result<Value, JcsDecodeError<R, Q>>

Decodes one complete JSON string into an owned value.

The string is interpreted as strict JSON with JCS binary64 number semantics. Resource usage is charged to this decoder’s cumulative session.

§Parameters
  • input is the complete UTF-8 JSON document to decode.
§Returns

The owned JSON value on success.

§Errors

Returns JcsDecodeError when syntax, JCS number constraints, or the configured resource limits reject the document.

Source

pub fn decode_value_str( &mut self, input: &str, ) -> Result<SafeJsonValue, JcsDecodeError<R, Q>>

Decodes a complete JSON string into a tree with protected cleanup.

The returned SafeJsonValue can be retained and dropped without recursive tree cleanup. Resource usage is charged to this decoder’s cumulative session exactly once. The same root-inclusive configured depth limit applies as for the legacy methods.

§Parameters
  • input is the complete UTF-8 JSON document to decode.
§Returns

The guarded owned JSON value on success.

§Errors

Returns JcsDecodeError for invalid JSON, unsupported JCS numbers, duplicate keys, or resource-limit violations. Accepted input bytes remain charged when materialization fails.

§Examples
use qubit_json::decode::JcsDecoder;
use qubit_json::encode::JcsEncoder;

let owner = JcsDecoder::unlimited()
    .decode_value_str(r#"{"b":2,"a":1}"#)
    .unwrap();
let bytes = JcsEncoder::unlimited().to_vec(owner.as_value()).unwrap();
assert_eq!(bytes, br#"{"a":1,"b":2}"#);
Source

pub fn decode_value_utf8( &mut self, input: &[u8], ) -> Result<SafeJsonValue, JcsDecodeError<R, Q>>

Decodes a complete UTF-8 JSON document into a tree with protected cleanup.

The guarded result supports iterative cleanup when dropped, including during panic unwinding. Its as_value() view can be passed to crate::encode::JcsEncoder. The configured root-inclusive depth limit and cumulative accounting session are shared with the legacy methods.

§Parameters
  • input is the complete UTF-8 JSON document to decode.
§Returns

The guarded owned JSON value on success.

§Errors

Returns JcsDecodeError for invalid JSON, unsupported JCS numbers, duplicate keys, or resource-limit violations. Input usage already admitted remains charged when later materialization fails.

Source

pub fn decode_utf8( &mut self, input: &[u8], ) -> Result<Value, JcsDecodeError<R, Q>>

Decodes one complete UTF-8 JSON document into an owned value.

The input is parsed with strict JSON and JCS binary64 number semantics; accepted resource usage is charged to the cumulative session.

§Parameters
  • input is the complete UTF-8 JSON document to decode.
§Returns

The owned JSON value on success.

§Errors

Returns JcsDecodeError for invalid JSON, unsupported JCS numbers, or resource-limit violations.

Source

pub fn decode_value_input<I>( &mut self, input: &mut I, ) -> Result<SafeJsonValue, JcsDecodeError<R, Q>>
where I: Input<Item = u8> + ?Sized,

Reads a complete byte input through EOF into a guarded JSON value.

The implementation buffers the full input before decoding. With a finite input budget it may read one uncharged probe byte beyond the limit to detect overflow; admitted bytes remain charged if decoding later fails. The guarded result supports iterative cleanup on drop.

§Type Parameters
  • I is the byte input implementation; it may be unsized.
§Parameters
  • input supplies the document bytes and is read through EOF or the first input-budget overflow probe.
§Returns

The guarded owned JSON value on success.

§Errors

Returns JcsDecodeError for input read failures, invalid JSON, duplicate keys, JCS number violations, or resource-limit violations.

Source

pub fn decode_input<I>( &mut self, input: &mut I, ) -> Result<Value, JcsDecodeError<R, Q>>
where I: Input<Item = u8> + ?Sized,

Reads a complete byte input through EOF and decodes it into an owned value.

A finite input budget permits one uncharged probe byte to detect overflow; accepted input bytes remain charged when later decoding fails.

§Type Parameters
  • I is the byte input implementation; it may be unsized.
§Parameters
  • input supplies the document bytes and is read through EOF.
§Returns

The owned JSON value on success.

§Errors

Returns JcsDecodeError for input read failures, invalid JSON, JCS number violations, or resource-limit violations.

Trait Implementations§

Source§

impl<'budget, R: Debug, Q> Debug for JcsDecoder<'budget, R, Q>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'budget, R = JsonResource, Q = usize> !UnwindSafe for JcsDecoder<'budget, R, Q>

§

impl<'budget, R, Q> Freeze for JcsDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: Freeze,

§

impl<'budget, R, Q> RefUnwindSafe for JcsDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: RefUnwindSafe,

§

impl<'budget, R, Q> Send for JcsDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: Send,

§

impl<'budget, R, Q> Sync for JcsDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: Sync,

§

impl<'budget, R, Q> Unpin for JcsDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: Unpin,

§

impl<'budget, R, Q> UnsafeUnpin for JcsDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.