use dlhn::{Body, Serializer}; use iai::main; use serde::Serialize; use serde_bytes::ByteBuf; use std::collections::BTreeMap; fn serialize_unit() -> Vec { serialize(Body::Unit) } fn serialize_optional() -> Vec { serialize(Body::Optional(Some(Box::new(Body::UInt8(u8::MAX))))) } fn serialize_bool() -> Vec { serialize(Body::Boolean(true)) } fn serialize_u8() -> Vec { serialize(Body::UInt8(u8::MAX)) } fn serialize_u16() -> Vec { serialize(Body::UInt16(u16::MAX)) } fn serialize_u32() -> Vec { serialize(Body::UInt32(u32::MAX)) } fn serialize_u64() -> Vec { serialize(Body::UInt64(u64::MAX)) } // fn serialize_u128() -> Vec { // serialize(Body::UInt128(u128::MAX)) // } fn serialize_i8() -> Vec { serialize(Body::Int8(i8::MAX)) } fn serialize_i16() -> Vec { serialize(Body::Int16(i16::MAX)) } fn serialize_i32() -> Vec { serialize(Body::Int32(i32::MAX)) } fn serialize_i64() -> Vec { serialize(Body::Int64(i64::MAX)) } // fn serialize_i128() -> Vec { // serialize(Body::Int128(i128::MAX)) // } fn serialize_array() -> Vec { serialize(Body::Array(vec![Body::Boolean(true), Body::Boolean(false)])) } fn serialize_tuple() -> Vec { serialize(Body::Tuple(vec![Body::Boolean(true), Body::Boolean(false)])) } // fn serialize_struct() -> Vec { // serialize(Body::Struct(vec![ // Body::Boolean(true), // Body::Boolean(false), // ])) // } fn serialize_map() -> Vec { serialize(Body::Map({ let mut buf = BTreeMap::new(); buf.insert("a".to_string(), Body::Boolean(true)); buf.insert("b".to_string(), Body::Boolean(false)); buf })) } fn serialize_enum() -> Vec { serialize(Body::Enum(0, Box::new(Body::Boolean(true)))) } fn serialize_binary() -> Vec { serialize(Body::Binary(ByteBuf::from((0..255).collect::>()))) } fn serialize(v: T) -> Vec { let mut buf = Vec::new(); let mut serializer = Serializer::new(&mut buf); v.serialize(&mut serializer).unwrap(); buf } main!( serialize_unit, serialize_optional, serialize_bool, serialize_u8, serialize_u16, serialize_u32, serialize_u64, // serialize_u128, serialize_i8, serialize_i16, serialize_i32, serialize_i64, // serialize_i128, serialize_array, serialize_tuple, // serialize_struct, serialize_map, serialize_enum, serialize_binary, );