}
/// Wrapper to read a required (non-optional) TLV record.
-pub struct RequiredWrapper<T: Readable>(pub Option<T>);
+pub struct RequiredWrapper<T>(pub Option<T>);
impl<T: Readable> Readable for RequiredWrapper<T> {
#[inline]
fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
Ok(Self(Some(Readable::read(reader)?)))
}
}
+impl<A, T: ReadableArgs<A>> ReadableArgs<A> for RequiredWrapper<T> {
+ #[inline]
+ fn read<R: Read>(reader: &mut R, args: A) -> Result<Self, DecodeError> {
+ Ok(Self(Some(ReadableArgs::read(reader, args)?)))
+ }
+}
/// When handling `default_values`, we want to map the default-value T directly
/// to a `RequiredWrapper<T>` in a way that works for `field: T = t;` as
/// well. Thus, we assume `Into<T> for T` does nothing and use that.
-impl<T: Readable> From<T> for RequiredWrapper<T> {
+impl<T> From<T> for RequiredWrapper<T> {
fn from(t: T) -> RequiredWrapper<T> { RequiredWrapper(Some(t)) }
}
($stream: expr, $type: expr, $field: expr, (option, encoding: $fieldty: ty)) => {
$crate::_encode_tlv!($stream, $type, $field, option);
};
+ ($stream: expr, $type: expr, $field: expr, (option: $trait: ident $(, $read_arg: expr)?)) => {
+ // Just a read-mapped type
+ $crate::_encode_tlv!($stream, $type, $field, option);
+ };
}
/// Panics if the last seen TLV type is not numerically less than the TLV type currently being checked.
$len.0 += field_len;
}
};
+ ($len: expr, $type: expr, $field: expr, (option: $trait: ident $(, $read_arg: expr)?)) => {
+ $crate::_get_varint_length_prefixed_tlv_length!($len, $type, $field, option);
+ };
($len: expr, $type: expr, $field: expr, upgradable_required) => {
$crate::_get_varint_length_prefixed_tlv_length!($len, $type, $field, required);
};
return Err(DecodeError::InvalidValue);
}
}};
+ ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (required: $trait: ident $(, $read_arg: expr)?)) => {{
+ $crate::_check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
+ }};
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, option) => {{
// no-op
}};
return Err(DecodeError::InvalidValue);
}
}};
+ ($last_seen_type: expr, $type: expr, $field: ident, (required: $trait: ident $(, $read_arg: expr)?)) => {{
+ $crate::_check_missing_tlv!($last_seen_type, $type, $field, required);
+ }};
($last_seen_type: expr, $type: expr, $field: ident, vec_type) => {{
// no-op
}};
($reader: expr, $field: ident, required) => {{
$field = $crate::util::ser::Readable::read(&mut $reader)?;
}};
+ ($reader: expr, $field: ident, (required: $trait: ident $(, $read_arg: expr)?)) => {{
+ $field = $trait::read(&mut $reader $(, $read_arg)*)?;
+ }};
($reader: expr, $field: ident, vec_type) => {{
let f: $crate::util::ser::WithoutLength<Vec<_>> = $crate::util::ser::Readable::read(&mut $reader)?;
$field = Some(f.0);
($field: ident, option) => {
$field
};
+ ($field: ident, (option: $trait: ident $(, $read_arg: expr)?)) => {
+ $crate::_init_tlv_based_struct_field!($field, option)
+ };
($field: ident, upgradable_required) => {
$field.0.unwrap()
};
($field: ident, required) => {
let mut $field = $crate::util::ser::RequiredWrapper(None);
};
+ ($field: ident, (required: $trait: ident $(, $read_arg: expr)?)) => {
+ $crate::_init_tlv_field_var!($field, required);
+ };
($field: ident, vec_type) => {
let mut $field = Some(Vec::new());
};
($field: ident, option) => {
let mut $field = None;
};
+ ($field: ident, (option: $trait: ident $(, $read_arg: expr)?)) => {
+ $crate::_init_tlv_field_var!($field, option);
+ };
($field: ident, upgradable_required) => {
let mut $field = $crate::util::ser::UpgradableRequired(None);
};