Struct CborCodec
pub struct CborCodec;Expand description
The CBOR codec. decode refuses input nested deeper than
[DEFAULT_MAX_DECODE_DEPTH] levels (cratestack#1315); use
CborCodec::with_max_depth for another limit.
Implementations§
§impl CborCodec
impl CborCodec
pub fn with_max_depth(max_depth: usize) -> CborCodecWithDepth
pub fn with_max_depth(max_depth: usize) -> CborCodecWithDepth
A codec whose decode accepts up to max_depth nested arrays, maps
and tags (a scalar is depth 0). Encoding is unchanged.
Trait Implementations§
§impl CratestackCodec for CborCodec
impl CratestackCodec for CborCodec
§fn encode_into<T>(
&self,
value: &T,
out: &mut Vec<u8>,
) -> Result<(), CratestackError>
fn encode_into<T>( &self, value: &T, out: &mut Vec<u8>, ) -> Result<(), CratestackError>
The serializer writes straight into out, so a signing envelope’s
seal_value (cratestack#1005) gets the payload in its own buffer with
no intermediate Vec. encode is this into an empty Vec, so the
two cannot drift apart.
§fn decode<T>(&self, bytes: &[u8]) -> Result<T, CratestackError>where
T: for<'de> Deserialize<'de>,
fn decode<T>(&self, bytes: &[u8]) -> Result<T, CratestackError>where
T: for<'de> Deserialize<'de>,
Decodes a CBOR value that must consume all of bytes, wrapped in
serde_path_to_error so the error’s detail names the field that
failed (failed to decode CBOR body: amountE8: ...). The public
message of CratestackError::Codec stays generic; the path reaches
operators through detail() only.
Unconsumed bytes are an error (#1153), as with JsonCodec::decode’s
trailing-characters check. minicbor_serde::from_slice would accept
them silently. This also refuses a unit variant sent as a one-entry map
({"A": null}): minicbor-serde 0.7.1’s unit_variant leaves the map
value unconsumed. A first-party encoder sends unit variants as plain
strings, so nothing legitimate is lost.
application/cbor-seq does not rely on this method to split items: the
buffered cratestack-client-rust decode_cbor_sequence walks items with
its own deserializer, and the streaming decoders cut each item at
Decoder::skip() boundaries before decoding the exact item bytes
(Flutter’s path then runs each item through this decode, where every
slice is exactly one item).
const CONTENT_TYPE: &'static str = "application/cbor"
fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CratestackError>
Source§impl HttpClientCodec for CborCodec
impl HttpClientCodec for CborCodec
fn accept_header_value(&self) -> &'static str
fn sequence_accept_header_value(&self) -> &'static str
fn decode_response<T>(
&self,
content_type: &str,
body: &[u8],
) -> Result<T, CratestackError>where
T: DeserializeOwned,
fn decode_sequence_response<T>(
&self,
content_type: &str,
body: &[u8],
) -> Result<Vec<T>, CratestackError>where
T: DeserializeOwned,
Source§fn payload_accept(&self) -> &'static str
fn payload_accept(&self) -> &'static str
Cratestack-Payload-Accept value: one to eight
lowercase type/subtype entries joined by ", ", in order of
preference. The default is CONTENT_TYPE
alone, which suits a codec that writes and reads the same type;
override it for an asymmetric one (a form in, JSON out). A sealed
call sends the header only when this is not application/cbor, and
the client refuses any answer sealed under a type it does not list.Auto Trait Implementations§
impl Freeze for CborCodec
impl RefUnwindSafe for CborCodec
impl Send for CborCodec
impl Sync for CborCodec
impl Unpin for CborCodec
impl UnsafeUnpin for CborCodec
impl UnwindSafe for CborCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more