#![allow(dead_code)]
use std::fmt::Debug;
use tree_buf::prelude::*;
use tree_buf::{Decodable, Encodable};
pub fn round_trip<T: Encodable + Decodable + Clone + std::fmt::Debug + PartialEq + 'static>(value: &T, root_size: impl Into<Option<i32>>, array_size: impl Into<Option<i32>>)
where
tree_buf::DecodeError: From<<<T as Decodable>::DecoderArray as tree_buf::internal::DecoderArray>::Error>,
{
serialize_eq(value, value, root_size);
let v = vec![value.clone(), value.clone()];
serialize_eq(&v, &v, array_size);
}
pub fn serialize_eq<I: Encodable, O: Decodable + Debug + PartialEq>(i: &I, o: &O, size: impl Into<Option<i32>>)
where
tree_buf::DecodeError: From<<<O as Decodable>::DecoderArray as tree_buf::internal::DecoderArray>::Error>,
{
let bytes = encode(i);
let result = decode(&bytes);
match result {
Ok(parsed) => assert_eq!(o, &parsed),
Err(e) => assert!(false, "{}", e),
}
if let Some(size) = size.into() {
assert_eq!(bytes.len() as i32, size, "Size Before: {}\nSize After: {}", size, bytes.len());
}
}
pub fn round_trip_default<T: Default + Decodable + Encodable + Debug + PartialEq + Clone + 'static>(root_size: i32, array_size: i32)
where
tree_buf::DecodeError: From<<<T as Decodable>::DecoderArray as tree_buf::internal::DecoderArray>::Error>,
{
let data = T::default();
round_trip(&data, root_size, array_size);
}