Available on crate features
io and codec-serde-json only.Expand description
Encoder/Decoder implementation with serde_json
This module provides a codec implementation for JSON serialization and deserialization using serde_json.
§Examples
use compio_io::framed::codec::{Decoder, Encoder, serde_json::SerdeJsonCodec};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct Person {
name: String,
age: u32,
}
let mut codec = SerdeJsonCodec::new();
let person = Person {
name: "Alice".to_string(),
age: 30,
};
// Encoding
let mut buffer = Vec::new();
codec.encode(person, &mut buffer).unwrap();
// Decoding
let decoded: Person = codec.decode(&buffer).unwrap();
assert_eq!(decoded.name, "Alice");
assert_eq!(decoded.age, 30);Structs§
- Serde
Json Codec - A codec for JSON serialization and deserialization using serde_json.
Enums§
- Serde
Json Codec Error - Errors that can occur during JSON encoding or decoding.