pub struct JcsDecoder<'budget, R = JsonResource, Q = usize>where
Q: ResourceQuantity,{ /* 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
Ris the resource kind tracked by the session.Qis 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,
impl<R, Q> JcsDecoder<'static, R, Q>where
R: Clone,
Q: ResourceQuantity,
Sourcepub fn with_limits(limits: JsonDecodeLimits<R, Q>) -> Self
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
limitscontains the resource ceilings for this decoder’s session.
§Returns
A decoder that owns a session initialized from limits.
Source§impl JcsDecoder<'static, JsonResource, usize>
impl JcsDecoder<'static, JsonResource, usize>
Sourcepub fn unlimited() -> Self
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,
impl<'budget, R, Q> JcsDecoder<'budget, R, Q>where
R: Clone,
Q: ResourceQuantity,
Sourcepub const fn new(session: JsonDecodeSession<'budget, R, Q>) -> Self
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
sessionis the accounting state to use for subsequent decodes.
§Returns
A decoder using the supplied session and redacted diagnostics.
Sourcepub const fn with_diagnostic_policy(self, policy: DiagnosticPolicy) -> Self
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
policydetermines whether decode errors redact input-derived data.
§Returns
This decoder with the selected diagnostic policy.
Sourcepub const fn diagnostic_policy(&self) -> DiagnosticPolicy
pub const fn diagnostic_policy(&self) -> DiagnosticPolicy
Returns the active diagnostic policy.
§Returns
The policy applied to errors from subsequent decode calls.
Sourcepub const fn session(&self) -> &JsonDecodeSession<'budget, R, Q>
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.
Sourcepub const fn session_mut(&mut self) -> &mut JsonDecodeSession<'budget, R, Q>
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.
Sourcepub fn into_session(self) -> JsonDecodeSession<'budget, R, Q>
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.
Sourcepub fn decode_str(&mut self, input: &str) -> Result<Value, JcsDecodeError<R, Q>>
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
inputis 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.
Sourcepub fn decode_value_str(
&mut self,
input: &str,
) -> Result<SafeJsonValue, JcsDecodeError<R, Q>>
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
inputis 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}"#);Sourcepub fn decode_value_utf8(
&mut self,
input: &[u8],
) -> Result<SafeJsonValue, JcsDecodeError<R, Q>>
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
inputis 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.
Sourcepub fn decode_utf8(
&mut self,
input: &[u8],
) -> Result<Value, JcsDecodeError<R, Q>>
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
inputis 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.
Sourcepub fn decode_value_input<I>(
&mut self,
input: &mut I,
) -> Result<SafeJsonValue, JcsDecodeError<R, Q>>
pub fn decode_value_input<I>( &mut self, input: &mut I, ) -> Result<SafeJsonValue, JcsDecodeError<R, Q>>
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
Iis the byte input implementation; it may be unsized.
§Parameters
inputsupplies 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.
Sourcepub fn decode_input<I>(
&mut self,
input: &mut I,
) -> Result<Value, JcsDecodeError<R, Q>>
pub fn decode_input<I>( &mut self, input: &mut I, ) -> Result<Value, JcsDecodeError<R, Q>>
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
Iis the byte input implementation; it may be unsized.
§Parameters
inputsupplies 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.