pub struct JsonCodec;Expand description
JSON codec using serde_json.
This is the default codec provided by moonpool. It’s great for debugging (human-readable output) but not the most efficient for production use.
§Example
use moonpool_core::{MessageCodec, JsonCodec};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Ping { seq: u32 }
let codec = JsonCodec;
let ping = Ping { seq: 1 };
let bytes = codec.encode(&ping).unwrap();
assert_eq!(&bytes, br#"{"seq":1}"#);
let decoded: Ping = codec.decode(&bytes).unwrap();
assert_eq!(decoded, ping);Trait Implementations§
Source§impl MessageCodec for JsonCodec
impl MessageCodec for JsonCodec
impl Copy for JsonCodec
Auto Trait Implementations§
impl Freeze for JsonCodec
impl RefUnwindSafe for JsonCodec
impl Send for JsonCodec
impl Sync for JsonCodec
impl Unpin for JsonCodec
impl UnwindSafe for JsonCodec
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
Mutably borrows from an owned value. Read more