|
|
@ -506,32 +506,19 @@ impl<T: ValueEncode> ValueEncode for Vec<T> { |
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
#[cfg(test)]
|
|
|
pub mod tests {
|
|
|
pub mod tests {
|
|
|
use std::fmt;
|
|
|
|
|
|
use std::net;
|
|
|
use std::net;
|
|
|
use std::u16;
|
|
|
use std::u16;
|
|
|
use std::u32;
|
|
|
use std::u32;
|
|
|
|
|
|
|
|
|
use bytes::{BufMut, BytesMut};
|
|
|
use bytes::{BufMut, BytesMut};
|
|
|
|
|
|
|
|
|
use super::{
|
|
|
|
|
|
ValueDecode, ValueDecodeError, ValueDecoder, ValueEncode, ValueEncoder,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
use crate::core::testing::roundtrip;
|
|
|
|
|
|
|
|
|
|
|
|
use super::{ValueDecodeError, ValueDecoder, ValueEncoder};
|
|
|
|
|
|
|
|
|
// Declared here because assert_eq!(bytes, &[]) fails to infer types.
|
|
|
// Declared here because assert_eq!(bytes, &[]) fails to infer types.
|
|
|
const EMPTY_BYTES: &'static [u8] = &[];
|
|
|
const EMPTY_BYTES: &'static [u8] = &[];
|
|
|
|
|
|
|
|
|
pub fn roundtrip<T>(input: T)
|
|
|
|
|
|
where
|
|
|
|
|
|
T: fmt::Debug + Eq + PartialEq + ValueEncode + ValueDecode,
|
|
|
|
|
|
{
|
|
|
|
|
|
let mut bytes = BytesMut::new();
|
|
|
|
|
|
|
|
|
|
|
|
ValueEncoder::new(&mut bytes).encode(&input).unwrap();
|
|
|
|
|
|
let output = ValueDecoder::new(&bytes).decode::<T>().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(output, input);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// A few integers and their corresponding byte encodings.
|
|
|
// A few integers and their corresponding byte encodings.
|
|
|
const U32_ENCODINGS: [(u32, [u8; 4]); 8] = [
|
|
|
const U32_ENCODINGS: [(u32, [u8; 4]); 8] = [
|
|
|
(0, [0, 0, 0, 0]),
|
|
|
(0, [0, 0, 0, 0]),
|
|
|
|