|
|
@ -260,10 +260,13 @@ impl<V: ?Sized + MessageValue> SerializedMessage<V>
|
|
|
|
};
|
|
|
|
};
|
|
|
|
(: $ser:expr) => {
|
|
|
|
(: $ser:expr) => {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
let ser = serde_cbor::to_vec($ser)?;
|
|
|
|
|
|
|
|
write!(u64::try_from(ser.len())?.to_be_bytes());
|
|
|
|
|
|
|
|
write!(ser);
|
|
|
|
|
|
|
|
/*
|
|
|
|
let mut w2 = WriteCounter(0, &mut writer);
|
|
|
|
let mut w2 = WriteCounter(0, &mut writer);
|
|
|
|
serde_cbor::to_writer(&mut w2, $ser)?;
|
|
|
|
serde_cbor::to_writer(&mut w2, $ser)?;
|
|
|
|
w+=w2.0;
|
|
|
|
w+=w2.0;*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -305,10 +308,18 @@ impl<V: ?Sized + MessageValue> SerializedMessage<V>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
(: $ser:ty) => {
|
|
|
|
(: $ser:ty) => {
|
|
|
|
serde_cbor::from_reader::<$ser, _>(&mut reader).wrap_err(eyre!("Failed to deserialise {} from reader", std::any::type_name::<$ser>()))?
|
|
|
|
{
|
|
|
|
};
|
|
|
|
let mut len = [0u8; std::mem::size_of::<u64>()];
|
|
|
|
(:) => {
|
|
|
|
read!(&mut len[..]);
|
|
|
|
serde_cbor::from_reader(&mut reader).wrap_err(eyre!("Failed to deserialise type from reader"))?
|
|
|
|
let len = usize::try_from(u64::from_be_bytes(len))?;
|
|
|
|
|
|
|
|
//TODO: Find realistic max size for `$ser`.
|
|
|
|
|
|
|
|
if len > MAX_ALLOC_SIZE {
|
|
|
|
|
|
|
|
return Err(eyre!("Invalid length read: {}", len));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut de = Vec::with_capacity(len);
|
|
|
|
|
|
|
|
read!(&mut de, len);
|
|
|
|
|
|
|
|
serde_cbor::from_slice::<$ser>(&de[..]).wrap_err(eyre!("Failed to deserialise {} from reader", std::any::type_name::<$ser>()))?
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
($into:expr, $num:expr) => {
|
|
|
|
($into:expr, $num:expr) => {
|
|
|
|
{
|
|
|
|
{
|
|
|
|