pub struct JsonBytesValueCodec<T> { /* private fields */ }Expand description
Encodes and decodes one serializable value through UTF-8 JSON bytes.
This type combines JsonBytesValueEncoder and JsonBytesValueDecoder
for registry-backed or bidirectional call sites. It holds no state between
calls, so it is Copy and Default, and encoding and decoding can share
one value through ValueEncoder and ValueDecoder.
§Type Parameters
T: Value type serialized to JSON bytes and recovered from them.
§Examples
use qubit_codec::JsonBytesValueCodec;
use qubit_codec::ValueDecoder;
use qubit_codec::ValueEncoder;
let mut codec = JsonBytesValueCodec::<String>::new();
assert_eq!(codec.encode(&"hello".to_string()).unwrap(), br#""hello""#.to_vec());
assert_eq!(codec.decode(br#""hello""#).unwrap(), "hello");Implementations§
Trait Implementations§
Source§impl<T: Clone> Clone for JsonBytesValueCodec<T>
impl<T: Clone> Clone for JsonBytesValueCodec<T>
impl<T: Copy> Copy for JsonBytesValueCodec<T>
Source§impl<T: Debug> Debug for JsonBytesValueCodec<T>
impl<T: Debug> Debug for JsonBytesValueCodec<T>
Source§impl<T: Default> Default for JsonBytesValueCodec<T>
impl<T: Default> Default for JsonBytesValueCodec<T>
Source§impl<T> ValueDecoder<[u8]> for JsonBytesValueCodec<T>where
T: DeserializeOwned,
impl<T> ValueDecoder<[u8]> for JsonBytesValueCodec<T>where
T: DeserializeOwned,
Source§fn decode(&mut self, input: &[u8]) -> Result<Self::Output, Self::Error>
fn decode(&mut self, input: &[u8]) -> Result<Self::Output, Self::Error>
Deserializes input from UTF-8 JSON bytes.
§Parameters
input: One complete UTF-8 JSON value, optionally surrounded by whitespace.
§Returns
Returns an owned T; decoding may allocate according to the target
type.
§Errors
Returns a JSON error for invalid UTF-8, malformed or incomplete input,
trailing non-whitespace data, or a value incompatible with T.
Source§impl<T> ValueEncoder<T> for JsonBytesValueCodec<T>where
T: Serialize,
impl<T> ValueEncoder<T> for JsonBytesValueCodec<T>where
T: Serialize,
Source§fn encode(&mut self, input: &T) -> Result<Self::Output, Self::Error>
fn encode(&mut self, input: &T) -> Result<Self::Output, Self::Error>
Serializes input into UTF-8 JSON bytes.
§Parameters
input: Value borrowed for the duration of serialization.
§Returns
Returns a newly allocated vector containing the serialized JSON.
§Errors
Returns a JSON error if T rejects serialization or contains a map key
that cannot be represented as a JSON object key.