diff --git a/pdl-compiler/src/backends/java/codegen/packet.rs b/pdl-compiler/src/backends/java/codegen/packet.rs index 9250bb33..92c38e03 100644 --- a/pdl-compiler/src/backends/java/codegen/packet.rs +++ b/pdl-compiler/src/backends/java/codegen/packet.rs @@ -851,8 +851,7 @@ fn declare_array_count( Some(WidthField::Size { elem_width: Some(elem_width), .. }) => { let elem_bytes = *elem_width / 8; let t = ExprTree::new(); - let root = - t.div(t.symbol(quote!($(name)Size), Integral::Int), t.num(elem_bytes)); + let root = t.div(t.symbol(quote!($(name)Size), Integral::Int), t.num(elem_bytes)); Some(quote!( if ($(name)Size % $elem_bytes != 0) { throw new IllegalArgumentException("Array size is not aligned to element size"); @@ -875,10 +874,8 @@ fn declare_array_count( { let elem_bytes = elem_width / 8; let t = ExprTree::new(); - let root = t.div( - t.symbol(quote!(buf.remaining()), Integral::Int), - t.num(elem_bytes), - ); + let root = + t.div(t.symbol(quote!(buf.remaining()), Integral::Int), t.num(elem_bytes)); Some(quote!( if (buf.remaining() % $elem_bytes != 0) { throw new IllegalArgumentException("Array size is not aligned to element size"); diff --git a/pdl-compiler/src/backends/java/test.rs b/pdl-compiler/src/backends/java/test.rs index 7799db7f..6b9c115f 100644 --- a/pdl-compiler/src/backends/java/test.rs +++ b/pdl-compiler/src/backends/java/test.rs @@ -182,7 +182,11 @@ impl TestVector { ) -> impl FormatInto + 'a { let packet_name = format!( "{}{}", - if self.unpacked.as_ref().unwrap().as_object().unwrap().contains_key("payload") { "Unknown" } else { "" }, + if self.unpacked.as_ref().unwrap().as_object().unwrap().contains_key("payload") { + "Unknown" + } else { + "" + }, self.packet .as_ref() .map(|child_id| Class::name_from_id(child_id)) diff --git a/pdl-compiler/src/backends/rust/decoder.rs b/pdl-compiler/src/backends/rust/decoder.rs index 1938018c..90f60209 100644 --- a/pdl-compiler/src/backends/rust/decoder.rs +++ b/pdl-compiler/src/backends/rust/decoder.rs @@ -111,7 +111,7 @@ impl<'a> FieldParser<'a> { let #id = (#cond_id == #cond_value) .then(|| #type_id::try_from(#value).map_err(|unknown_val| { - DecodeError::InvalidEnumValueError { + DecodeError::EnumValueError { obj: #decl_id, field: #name, value: unknown_val as u64, @@ -207,7 +207,7 @@ impl<'a> FieldParser<'a> { quote! { let fixed_value = #v; if fixed_value != #value_type::from(#enum_id::#tag_id) { - return Err(DecodeError::InvalidFixedValue { + return Err(DecodeError::FixedValueError { expected: #value_type::from(#enum_id::#tag_id) as u64, actual: fixed_value as u64, }); @@ -219,7 +219,7 @@ impl<'a> FieldParser<'a> { quote! { let fixed_value = #v; if fixed_value != #value { - return Err(DecodeError::InvalidFixedValue { + return Err(DecodeError::FixedValueError { expected: #value, actual: fixed_value as u64, }); @@ -233,7 +233,7 @@ impl<'a> FieldParser<'a> { let id = id.to_ident(); let type_id = type_id.to_ident(); quote! { - let #id = #type_id::try_from(#v).map_err(|unknown_val| DecodeError::InvalidEnumValueError { + let #id = #type_id::try_from(#v).map_err(|unknown_val| DecodeError::EnumValueError { obj: #packet_name, field: #field_name, value: unknown_val as u64, @@ -327,7 +327,7 @@ impl<'a> FieldParser<'a> { let packet_name = &self.packet_name; self.tokens.extend(quote! { if #span.remaining() < #wanted { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: #packet_name, wanted: #wanted, got: #span.remaining(), @@ -438,7 +438,7 @@ impl<'a> FieldParser<'a> { } let #id = #id .try_into() - .map_err(|_| DecodeError::InvalidPacketError)?; + .map_err(|_| DecodeError::UnwrapError)?; }); } (ElementWidth::Unknown, ArrayShape::CountField(count_field)) => { @@ -483,7 +483,7 @@ impl<'a> FieldParser<'a> { } let #id = #id .try_into() - .map_err(|_| DecodeError::InvalidPacketError)?; + .map_err(|_| DecodeError::UnwrapError)?; }); } (ElementWidth::Static(element_width), ArrayShape::CountField(count_field)) => { @@ -512,7 +512,7 @@ impl<'a> FieldParser<'a> { let element_width = proc_macro2::Literal::usize_unsuffixed(element_width); self.tokens.extend(quote! { if #array_size % #element_width != 0 { - return Err(DecodeError::InvalidArraySize { + return Err(DecodeError::ArraySizeError { array: #array_size, element: #element_width, }); @@ -565,7 +565,7 @@ impl<'a> FieldParser<'a> { #span = &#span[#array_size..]; let #id = #id .try_into() - .map_err(|_| DecodeError::InvalidPacketError)?; + .map_err(|_| DecodeError::UnwrapError)?; }); } (ElementWidth::Dynamic(element_size_field), ArrayShape::CountField(count_field)) => { @@ -606,7 +606,7 @@ impl<'a> FieldParser<'a> { }; self.tokens.extend(quote! { if #array_size % #element_size_field != 0 { - return Err(DecodeError::InvalidArraySize { + return Err(DecodeError::ArraySizeError { array: #array_size, element: #element_size_field, }); @@ -706,7 +706,7 @@ impl<'a> FieldParser<'a> { // size. self.tokens.extend(quote! { if #size_field < #size_modifier { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: #packet_name, wanted: #size_modifier, got: #size_field, @@ -772,7 +772,7 @@ impl<'a> FieldParser<'a> { let type_id = id.to_ident(); let packet_name = &self.packet_name; return quote! { - #type_id::try_from(#get_uint).map_err(|unknown_val| DecodeError::InvalidEnumValueError { + #type_id::try_from(#get_uint).map_err(|unknown_val| DecodeError::EnumValueError { obj: #packet_name, field: "", // TODO(mgeisler): fill out or remove value: unknown_val as u64, diff --git a/pdl-compiler/src/backends/rust/mod.rs b/pdl-compiler/src/backends/rust/mod.rs index 9df40b56..daf8b7f9 100644 --- a/pdl-compiler/src/backends/rust/mod.rs +++ b/pdl-compiler/src/backends/rust/mod.rs @@ -713,7 +713,7 @@ fn generate_derived_packet_decl( let value_str = constraint_value_str(&parent_data_fields, c); quote! { if parent.#field_id() != #value { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: #packet_name, field: #field_name, expected: #value_str, @@ -740,7 +740,7 @@ fn generate_derived_packet_decl( #( #cloned_field_ids: parent.#cloned_field_ids.clone(), )* }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } } @@ -1240,7 +1240,7 @@ fn generate_custom_field_decl( impl Packet for #id { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < #size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: #name, wanted: #size, got: buf.len(), diff --git a/pdl-compiler/src/backends/rust/test.rs b/pdl-compiler/src/backends/rust/test.rs index df4d77b0..34c707df 100644 --- a/pdl-compiler/src/backends/rust/test.rs +++ b/pdl-compiler/src/backends/rust/test.rs @@ -47,12 +47,12 @@ fn to_json(value: &T) -> syn::LitStr { /// Map an error variant name to a `matches!` pattern for `DecodeError`. /// -/// Unit variants like `"TrailingBytes"` become `DecodeError::TrailingBytes`. -/// Struct variants like `"InvalidLengthError"` become `DecodeError::InvalidLengthError { .. }`. +/// Unit variants like `"TrailingBytesError"` become `DecodeError::TrailingBytesError`. +/// Struct variants like `"LengthError"` become `DecodeError::LengthError { .. }`. fn error_variant_pattern(variant: &str) -> proc_macro2::TokenStream { let variant_ident = format_ident!("{}", variant); match variant { - "InvalidPacketError" | "ImpossibleStructError" | "TrailingBytes" => { + "UnwrapError" | "TrailingBytesError" => { quote! { DecodeError::#variant_ident } } _ => { @@ -118,9 +118,9 @@ fn generate_unit_tests(input: &str, packet_names: &[&str]) -> Result for u32 { impl Packet for ExactSize { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < 4 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "ExactSize", wanted: 4, got: buf.len(), @@ -78,7 +78,7 @@ impl From for u32 { impl Packet for TruncatedSize { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "TruncatedSize", wanted: 3, got: buf.len(), diff --git a/pdl-compiler/tests/generated/rust/custom_field_declaration_little_endian.rs b/pdl-compiler/tests/generated/rust/custom_field_declaration_little_endian.rs index 3fbe08d9..c8066b8a 100644 --- a/pdl-compiler/tests/generated/rust/custom_field_declaration_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/custom_field_declaration_little_endian.rs @@ -40,7 +40,7 @@ impl From for u32 { impl Packet for ExactSize { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < 4 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "ExactSize", wanted: 4, got: buf.len(), @@ -78,7 +78,7 @@ impl From for u32 { impl Packet for TruncatedSize { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "TruncatedSize", wanted: 3, got: buf.len(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_array_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_array_big_endian.rs index 1ac1d0ef..7a2d478d 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_array_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_array_big_endian.rs @@ -103,7 +103,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 * 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 5 * 3, got: buf.remaining(), @@ -113,7 +113,7 @@ impl Packet for Bar { for _ in 0..5 { x.push( Foo::try_from(buf.get_uint(3) as u32) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "", value: unknown_val as u64, @@ -121,7 +121,7 @@ impl Packet for Bar { })?, ) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_array_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_array_little_endian.rs index cca3332f..45148367 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_array_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_array_little_endian.rs @@ -103,7 +103,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 * 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 5 * 3, got: buf.remaining(), @@ -113,7 +113,7 @@ impl Packet for Bar { for _ in 0..5 { x.push( Foo::try_from(buf.get_uint_le(3) as u32) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "", value: unknown_val as u64, @@ -121,7 +121,7 @@ impl Packet for Bar { })?, ) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_big_endian.rs index fc99d1b4..164f43e4 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_big_endian.rs @@ -99,14 +99,14 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 3, got: buf.remaining(), }); } let x = Foo::try_from(buf.get_uint(3) as u32) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "x", value: unknown_val as u64, diff --git a/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_little_endian.rs index b399a342..24988d71 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_24bit_enum_little_endian.rs @@ -99,14 +99,14 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 3, got: buf.remaining(), }); } let x = Foo::try_from(buf.get_uint_le(3) as u32) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "x", value: unknown_val as u64, diff --git a/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_array_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_array_big_endian.rs index 87772915..ac70a025 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_array_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_array_big_endian.rs @@ -50,7 +50,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 * 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 5 * 3, got: buf.remaining(), @@ -60,7 +60,7 @@ impl Packet for Foo { for _ in 0..5 { x.push(Ok::<_, DecodeError>(buf.get_uint(3) as u32)?) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_array_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_array_little_endian.rs index 5cd29d92..15598d44 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_array_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_array_little_endian.rs @@ -50,7 +50,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 * 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 5 * 3, got: buf.remaining(), @@ -60,7 +60,7 @@ impl Packet for Foo { for _ in 0..5 { x.push(Ok::<_, DecodeError>(buf.get_uint_le(3) as u32)?) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_big_endian.rs index cedde10b..92b7a3a1 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_big_endian.rs @@ -56,7 +56,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_little_endian.rs index a02cd4e9..bd3dad2e 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_24bit_scalar_little_endian.rs @@ -56,7 +56,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_array_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_array_big_endian.rs index a6640b3f..8e46cffa 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_array_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_array_big_endian.rs @@ -88,7 +88,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 7 * 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 7 * 8, got: buf.remaining(), @@ -98,7 +98,7 @@ impl Packet for Bar { for _ in 0..7 { x.push( Foo::try_from(buf.get_u64()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "", value: unknown_val as u64, @@ -106,7 +106,7 @@ impl Packet for Bar { })?, ) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_array_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_array_little_endian.rs index 578e8718..7c7eef04 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_array_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_array_little_endian.rs @@ -88,7 +88,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 7 * 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 7 * 8, got: buf.remaining(), @@ -98,7 +98,7 @@ impl Packet for Bar { for _ in 0..7 { x.push( Foo::try_from(buf.get_u64_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "", value: unknown_val as u64, @@ -106,7 +106,7 @@ impl Packet for Bar { })?, ) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_big_endian.rs index 51f2047b..1534f580 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_big_endian.rs @@ -84,14 +84,14 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 8, got: buf.remaining(), }); } let x = Foo::try_from(buf.get_u64()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "x", value: unknown_val as u64, diff --git a/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_little_endian.rs index 380d78a6..d332f1c9 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_64bit_enum_little_endian.rs @@ -84,14 +84,14 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 8, got: buf.remaining(), }); } let x = Foo::try_from(buf.get_u64_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "x", value: unknown_val as u64, diff --git a/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_array_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_array_big_endian.rs index 3d5f926b..1f916991 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_array_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_array_big_endian.rs @@ -50,7 +50,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 7 * 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 7 * 8, got: buf.remaining(), @@ -60,7 +60,7 @@ impl Packet for Foo { for _ in 0..7 { x.push(Ok::<_, DecodeError>(buf.get_u64())?) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_array_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_array_little_endian.rs index 77f4f4d2..4acc9e98 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_array_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_array_little_endian.rs @@ -50,7 +50,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 7 * 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 7 * 8, got: buf.remaining(), @@ -60,7 +60,7 @@ impl Packet for Foo { for _ in 0..7 { x.push(Ok::<_, DecodeError>(buf.get_u64_le())?) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_big_endian.rs index b1219dd6..a1172ed5 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_big_endian.rs @@ -48,7 +48,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 8, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_little_endian.rs index 2d8c8e00..7a2aef33 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_64bit_scalar_little_endian.rs @@ -48,7 +48,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 8, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_array_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_array_big_endian.rs index ddeb57b7..f0865947 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_array_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_array_big_endian.rs @@ -118,7 +118,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 3, got: buf.remaining(), @@ -128,7 +128,7 @@ impl Packet for Bar { for _ in 0..3 { x.push( Foo::try_from(buf.get_u8()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "", value: unknown_val as u64, @@ -136,7 +136,7 @@ impl Packet for Bar { })?, ) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_array_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_array_little_endian.rs index ddeb57b7..f0865947 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_array_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_array_little_endian.rs @@ -118,7 +118,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 3, got: buf.remaining(), @@ -128,7 +128,7 @@ impl Packet for Bar { for _ in 0..3 { x.push( Foo::try_from(buf.get_u8()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "", value: unknown_val as u64, @@ -136,7 +136,7 @@ impl Packet for Bar { })?, ) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_big_endian.rs index 2f58ef58..bb766718 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_big_endian.rs @@ -114,14 +114,14 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), }); } let x = Foo::try_from(buf.get_u8()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "x", value: unknown_val as u64, diff --git a/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_little_endian.rs index 2f58ef58..bb766718 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_8bit_enum_little_endian.rs @@ -114,14 +114,14 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), }); } let x = Foo::try_from(buf.get_u8()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Bar", field: "x", value: unknown_val as u64, diff --git a/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_array_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_array_big_endian.rs index 8f3b7850..1abcbc87 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_array_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_array_big_endian.rs @@ -50,7 +50,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), @@ -60,7 +60,7 @@ impl Packet for Foo { for _ in 0..3 { x.push(Ok::<_, DecodeError>(buf.get_u8())?) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_array_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_array_little_endian.rs index 8f3b7850..1abcbc87 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_array_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_array_little_endian.rs @@ -50,7 +50,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), @@ -60,7 +60,7 @@ impl Packet for Foo { for _ in 0..3 { x.push(Ok::<_, DecodeError>(buf.get_u8())?) } - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_big_endian.rs index 27e16423..e316001b 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_big_endian.rs @@ -48,7 +48,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_little_endian.rs index 27e16423..e316001b 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_8bit_scalar_little_endian.rs @@ -48,7 +48,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_count_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_count_big_endian.rs index fa6dd5ff..b96b738f 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_count_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_count_big_endian.rs @@ -72,7 +72,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -82,7 +82,7 @@ impl Packet for Foo { let x_count = (chunk & 0x1f) as usize; let padding = ((chunk >> 5) & 0x7); if buf.remaining() < x_count * 3usize { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: x_count * 3usize, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_count_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_count_little_endian.rs index db61324d..384bad34 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_count_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_count_little_endian.rs @@ -72,7 +72,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -82,7 +82,7 @@ impl Packet for Foo { let x_count = (chunk & 0x1f) as usize; let padding = ((chunk >> 5) & 0x7); if buf.remaining() < x_count * 3usize { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: x_count * 3usize, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_big_endian.rs index 930dfcba..98393a5c 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_big_endian.rs @@ -118,7 +118,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -128,7 +128,7 @@ impl Packet for Bar { let x_element_size = (chunk & 0x1f) as usize; let padding = ((chunk >> 5) & 0x7); if buf.remaining() % x_element_size != 0 { - return Err(DecodeError::InvalidArraySize { + return Err(DecodeError::ArraySizeError { array: buf.remaining(), element: x_element_size, }); diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_count_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_count_big_endian.rs index 4646c5be..8805264b 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_count_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_count_big_endian.rs @@ -114,7 +114,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -124,7 +124,7 @@ impl Packet for Bar { let x_count = (chunk & 0xf) as usize; let x_element_size = ((chunk >> 4) & 0xf) as usize; if buf.remaining() < x_count * x_element_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: x_count * x_element_size, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_count_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_count_little_endian.rs index 4646c5be..8805264b 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_count_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_count_little_endian.rs @@ -114,7 +114,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -124,7 +124,7 @@ impl Packet for Bar { let x_count = (chunk & 0xf) as usize; let x_element_size = ((chunk >> 4) & 0xf) as usize; if buf.remaining() < x_count * x_element_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: x_count * x_element_size, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_size_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_size_big_endian.rs index 2adcb026..042bc827 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_size_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_size_big_endian.rs @@ -116,7 +116,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -126,14 +126,14 @@ impl Packet for Bar { let x_size = (chunk & 0xf) as usize; let x_element_size = ((chunk >> 4) & 0xf) as usize; if buf.remaining() < x_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: x_size, got: buf.remaining(), }); } if x_size % x_element_size != 0 { - return Err(DecodeError::InvalidArraySize { + return Err(DecodeError::ArraySizeError { array: x_size, element: x_element_size, }); diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_size_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_size_little_endian.rs index 2adcb026..042bc827 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_size_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_dynamic_size_little_endian.rs @@ -116,7 +116,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -126,14 +126,14 @@ impl Packet for Bar { let x_size = (chunk & 0xf) as usize; let x_element_size = ((chunk >> 4) & 0xf) as usize; if buf.remaining() < x_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: x_size, got: buf.remaining(), }); } if x_size % x_element_size != 0 { - return Err(DecodeError::InvalidArraySize { + return Err(DecodeError::ArraySizeError { array: x_size, element: x_element_size, }); diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_little_endian.rs index 930dfcba..98393a5c 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_little_endian.rs @@ -118,7 +118,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -128,7 +128,7 @@ impl Packet for Bar { let x_element_size = (chunk & 0x1f) as usize; let padding = ((chunk >> 5) & 0x7); if buf.remaining() % x_element_size != 0 { - return Err(DecodeError::InvalidArraySize { + return Err(DecodeError::ArraySizeError { array: buf.remaining(), element: x_element_size, }); diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_1_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_1_big_endian.rs index 316bd3c9..160d920c 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_1_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_1_big_endian.rs @@ -121,7 +121,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -131,7 +131,7 @@ impl Packet for Bar { let x_element_size = (chunk & 0x1f) as usize; let padding = ((chunk >> 5) & 0x7); if buf.remaining() < x_element_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: x_element_size, got: buf.remaining(), @@ -155,7 +155,7 @@ impl Packet for Bar { }) .collect::, DecodeError>>()?; buf = &buf[x_element_size..]; - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { padding, x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_1_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_1_little_endian.rs index 316bd3c9..160d920c 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_1_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_1_little_endian.rs @@ -121,7 +121,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -131,7 +131,7 @@ impl Packet for Bar { let x_element_size = (chunk & 0x1f) as usize; let padding = ((chunk >> 5) & 0x7); if buf.remaining() < x_element_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: x_element_size, got: buf.remaining(), @@ -155,7 +155,7 @@ impl Packet for Bar { }) .collect::, DecodeError>>()?; buf = &buf[x_element_size..]; - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { padding, x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_big_endian.rs index fdfd0030..ea10d97a 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_big_endian.rs @@ -121,7 +121,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -131,7 +131,7 @@ impl Packet for Bar { let x_element_size = (chunk & 0x1f) as usize; let padding = ((chunk >> 5) & 0x7); if buf.remaining() < 4usize * x_element_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 4usize * x_element_size, got: buf.remaining(), @@ -155,7 +155,7 @@ impl Packet for Bar { }) .collect::, DecodeError>>()?; buf = &buf[4usize * x_element_size..]; - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { padding, x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_little_endian.rs index fdfd0030..ea10d97a 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_element_size_static_count_little_endian.rs @@ -121,7 +121,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -131,7 +131,7 @@ impl Packet for Bar { let x_element_size = (chunk & 0x1f) as usize; let padding = ((chunk >> 5) & 0x7); if buf.remaining() < 4usize * x_element_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 4usize * x_element_size, got: buf.remaining(), @@ -155,7 +155,7 @@ impl Packet for Bar { }) .collect::, DecodeError>>()?; buf = &buf[4usize * x_element_size..]; - let x = x.try_into().map_err(|_| DecodeError::InvalidPacketError)?; + let x = x.try_into().map_err(|_| DecodeError::UnwrapError)?; Ok((Self { padding, x }, buf)) } } diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_size_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_size_big_endian.rs index 9fc6b4dc..1a039f02 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_size_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_size_big_endian.rs @@ -73,7 +73,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -83,14 +83,14 @@ impl Packet for Foo { let x_size = (chunk & 0x1f) as usize; let padding = ((chunk >> 5) & 0x7); if buf.remaining() < x_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: x_size, got: buf.remaining(), }); } if x_size % 3 != 0 { - return Err(DecodeError::InvalidArraySize { + return Err(DecodeError::ArraySizeError { array: x_size, element: 3, }); diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_size_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_size_little_endian.rs index e9677f04..e4990e86 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_size_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_dynamic_size_little_endian.rs @@ -73,7 +73,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -83,14 +83,14 @@ impl Packet for Foo { let x_size = (chunk & 0x1f) as usize; let padding = ((chunk >> 5) & 0x7); if buf.remaining() < x_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: x_size, got: buf.remaining(), }); } if x_size % 3 != 0 { - return Err(DecodeError::InvalidArraySize { + return Err(DecodeError::ArraySizeError { array: x_size, element: 3, }); diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_count_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_count_big_endian.rs index d4be35dc..a69d7369 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_count_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_count_big_endian.rs @@ -59,7 +59,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 5, got: buf.remaining(), @@ -67,7 +67,7 @@ impl Packet for Foo { } let a_count = buf.get_uint(5) as usize; if buf.remaining() < a_count * 2usize { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: a_count * 2usize, got: buf.remaining(), @@ -115,7 +115,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 5, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_count_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_count_little_endian.rs index 5853656d..1c64aff7 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_count_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_count_little_endian.rs @@ -59,7 +59,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 5, got: buf.remaining(), @@ -67,7 +67,7 @@ impl Packet for Foo { } let a_count = buf.get_uint_le(5) as usize; if buf.remaining() < a_count * 2usize { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: a_count * 2usize, got: buf.remaining(), @@ -115,7 +115,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 5, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_size_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_size_big_endian.rs index a614e8ab..7d1d0ad4 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_size_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_size_big_endian.rs @@ -59,7 +59,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 5, got: buf.remaining(), @@ -67,7 +67,7 @@ impl Packet for Foo { } let a_count = buf.get_uint(5) as usize; if buf.remaining() < a_count * 2usize { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: a_count * 2usize, got: buf.remaining(), @@ -117,7 +117,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 5, got: buf.remaining(), @@ -125,7 +125,7 @@ impl Packet for Bar { } let x_size = buf.get_uint(5) as usize; if buf.remaining() < x_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: x_size, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_size_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_size_little_endian.rs index 35b7cfb1..76347eba 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_size_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_unknown_element_width_dynamic_size_little_endian.rs @@ -59,7 +59,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 5, got: buf.remaining(), @@ -67,7 +67,7 @@ impl Packet for Foo { } let a_count = buf.get_uint_le(5) as usize; if buf.remaining() < a_count * 2usize { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: a_count * 2usize, got: buf.remaining(), @@ -117,7 +117,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 5, got: buf.remaining(), @@ -125,7 +125,7 @@ impl Packet for Bar { } let x_size = buf.get_uint_le(5) as usize; if buf.remaining() < x_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: x_size, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_with_padding_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_with_padding_big_endian.rs index 51f21b8f..3e490af0 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_with_padding_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_with_padding_big_endian.rs @@ -59,7 +59,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 5, got: buf.remaining(), @@ -67,7 +67,7 @@ impl Packet for Foo { } let a_count = buf.get_uint(5) as usize; if buf.remaining() < a_count * 2usize { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: a_count * 2usize, got: buf.remaining(), @@ -116,7 +116,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 128usize { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 128usize, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_array_with_padding_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_array_with_padding_little_endian.rs index c958b24b..c5b2dc4e 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_array_with_padding_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_array_with_padding_little_endian.rs @@ -59,7 +59,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 5, got: buf.remaining(), @@ -67,7 +67,7 @@ impl Packet for Foo { } let a_count = buf.get_uint_le(5) as usize; if buf.remaining() < a_count * 2usize { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: a_count * 2usize, got: buf.remaining(), @@ -116,7 +116,7 @@ impl Packet for Bar { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 128usize { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 128usize, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_child_packets_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_child_packets_big_endian.rs index 6c7d63ee..099fbd4f 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_child_packets_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_child_packets_big_endian.rs @@ -145,7 +145,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -153,21 +153,21 @@ impl Packet for Foo { } let a = buf.get_u8(); if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), }); } let b = Enum16::try_from(buf.get_u16()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Foo", field: "b", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -175,7 +175,7 @@ impl Packet for Foo { } let payload_size = buf.get_u8() as usize; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: payload_size, got: buf.remaining(), @@ -226,7 +226,7 @@ impl Bar { fn decode_partial(parent: &Foo) -> Result { let mut buf: &[u8] = &parent.payload; if parent.a() != 100 { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Bar", field: "a", expected: "100", @@ -234,7 +234,7 @@ impl Bar { }); } if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -244,7 +244,7 @@ impl Bar { if buf.is_empty() { Ok(Self { x, b: parent.b }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -332,7 +332,7 @@ impl Baz { fn decode_partial(parent: &Foo) -> Result { let mut buf: &[u8] = &parent.payload; if parent.b() != Enum16::B { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Baz", field: "b", expected: "Enum16::B", @@ -340,7 +340,7 @@ impl Baz { }); } if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Baz", wanted: 2, got: buf.remaining(), @@ -350,7 +350,7 @@ impl Baz { if buf.is_empty() { Ok(Self { y, a: parent.a }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { diff --git a/pdl-compiler/tests/generated/rust/packet_decl_child_packets_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_child_packets_little_endian.rs index 8a8e4bc8..12b399ab 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_child_packets_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_child_packets_little_endian.rs @@ -145,7 +145,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -153,21 +153,21 @@ impl Packet for Foo { } let a = buf.get_u8(); if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), }); } let b = Enum16::try_from(buf.get_u16_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Foo", field: "b", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -175,7 +175,7 @@ impl Packet for Foo { } let payload_size = buf.get_u8() as usize; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: payload_size, got: buf.remaining(), @@ -226,7 +226,7 @@ impl Bar { fn decode_partial(parent: &Foo) -> Result { let mut buf: &[u8] = &parent.payload; if parent.a() != 100 { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Bar", field: "a", expected: "100", @@ -234,7 +234,7 @@ impl Bar { }); } if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -244,7 +244,7 @@ impl Bar { if buf.is_empty() { Ok(Self { x, b: parent.b }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -332,7 +332,7 @@ impl Baz { fn decode_partial(parent: &Foo) -> Result { let mut buf: &[u8] = &parent.payload; if parent.b() != Enum16::B { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Baz", field: "b", expected: "Enum16::B", @@ -340,7 +340,7 @@ impl Baz { }); } if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Baz", wanted: 2, got: buf.remaining(), @@ -350,7 +350,7 @@ impl Baz { if buf.is_empty() { Ok(Self { y, a: parent.a }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { diff --git a/pdl-compiler/tests/generated/rust/packet_decl_complex_scalars_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_complex_scalars_big_endian.rs index b8325359..addac7ca 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_complex_scalars_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_complex_scalars_big_endian.rs @@ -120,7 +120,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), @@ -131,7 +131,7 @@ impl Packet for Foo { let b = (chunk >> 3) as u8; let c = ((chunk >> 11) & 0x1f) as u8; if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), @@ -139,7 +139,7 @@ impl Packet for Foo { } let d = buf.get_uint(3) as u32; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_complex_scalars_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_complex_scalars_little_endian.rs index a2f37877..c681c422 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_complex_scalars_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_complex_scalars_little_endian.rs @@ -120,7 +120,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), @@ -131,7 +131,7 @@ impl Packet for Foo { let b = (chunk >> 3) as u8; let c = ((chunk >> 11) & 0x1f) as u8; if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), @@ -139,7 +139,7 @@ impl Packet for Foo { } let d = buf.get_uint_le(3) as u32; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_custom_field_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_custom_field_big_endian.rs index 7d89ee16..5d7f5302 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_custom_field_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_custom_field_big_endian.rs @@ -40,7 +40,7 @@ impl From for u32 { impl Packet for Bar1 { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar1", wanted: 3, got: buf.len(), @@ -79,7 +79,7 @@ impl From for u32 { impl Packet for Bar2 { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < 4 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar2", wanted: 4, got: buf.len(), @@ -117,7 +117,7 @@ impl From for u64 { impl Packet for Bar3 { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar3", wanted: 8, got: buf.len(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_custom_field_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_custom_field_little_endian.rs index ac4e3bba..fa9d46c7 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_custom_field_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_custom_field_little_endian.rs @@ -40,7 +40,7 @@ impl From for u32 { impl Packet for Bar1 { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar1", wanted: 3, got: buf.len(), @@ -79,7 +79,7 @@ impl From for u32 { impl Packet for Bar2 { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < 4 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar2", wanted: 4, got: buf.len(), @@ -117,7 +117,7 @@ impl From for u64 { impl Packet for Bar3 { fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.len() < 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar3", wanted: 8, got: buf.len(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_fixed_enum_field_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_fixed_enum_field_big_endian.rs index 9d139083..602c2a56 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_fixed_enum_field_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_fixed_enum_field_big_endian.rs @@ -128,7 +128,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 8, got: buf.remaining(), @@ -137,7 +137,7 @@ impl Packet for Foo { let chunk = buf.get_u64(); let fixed_value = (chunk & 0x7f) as u8; if fixed_value != u8::from(Enum7::A) { - return Err(DecodeError::InvalidFixedValue { + return Err(DecodeError::FixedValueError { expected: u8::from(Enum7::A) as u64, actual: fixed_value as u64, }); diff --git a/pdl-compiler/tests/generated/rust/packet_decl_fixed_enum_field_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_fixed_enum_field_little_endian.rs index 17622ea5..1f17c337 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_fixed_enum_field_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_fixed_enum_field_little_endian.rs @@ -128,7 +128,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 8, got: buf.remaining(), @@ -137,7 +137,7 @@ impl Packet for Foo { let chunk = buf.get_u64_le(); let fixed_value = (chunk & 0x7f) as u8; if fixed_value != u8::from(Enum7::A) { - return Err(DecodeError::InvalidFixedValue { + return Err(DecodeError::FixedValueError { expected: u8::from(Enum7::A) as u64, actual: fixed_value as u64, }); diff --git a/pdl-compiler/tests/generated/rust/packet_decl_fixed_scalar_field_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_fixed_scalar_field_big_endian.rs index 0d7e20a3..4b6fbe59 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_fixed_scalar_field_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_fixed_scalar_field_big_endian.rs @@ -57,7 +57,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 8, got: buf.remaining(), @@ -66,7 +66,7 @@ impl Packet for Foo { let chunk = buf.get_u64(); let fixed_value = (chunk & 0x7f) as u8; if fixed_value != 7 { - return Err(DecodeError::InvalidFixedValue { + return Err(DecodeError::FixedValueError { expected: 7, actual: fixed_value as u64, }); diff --git a/pdl-compiler/tests/generated/rust/packet_decl_fixed_scalar_field_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_fixed_scalar_field_little_endian.rs index a2cb575d..0c90e754 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_fixed_scalar_field_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_fixed_scalar_field_little_endian.rs @@ -57,7 +57,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 8 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 8, got: buf.remaining(), @@ -66,7 +66,7 @@ impl Packet for Foo { let chunk = buf.get_u64_le(); let fixed_value = (chunk & 0x7f) as u8; if fixed_value != 7 { - return Err(DecodeError::InvalidFixedValue { + return Err(DecodeError::FixedValueError { expected: 7, actual: fixed_value as u64, }); diff --git a/pdl-compiler/tests/generated/rust/packet_decl_grand_children_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_grand_children_big_endian.rs index a4d75f88..2eec9f90 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_grand_children_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_grand_children_big_endian.rs @@ -153,49 +153,49 @@ impl Packet for Parent { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let foo = Enum16::try_from(buf.get_u16()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "foo", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let bar = Enum16::try_from(buf.get_u16()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "bar", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let baz = Enum16::try_from(buf.get_u16()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "baz", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 1, got: buf.remaining(), @@ -203,7 +203,7 @@ impl Packet for Parent { } let payload_size = buf.get_u8() as usize; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: payload_size, got: buf.remaining(), @@ -274,7 +274,7 @@ impl Child { fn decode_partial(parent: &Parent) -> Result { let mut buf: &[u8] = &parent.payload; if parent.foo() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Child", field: "foo", expected: "Enum16::A", @@ -282,14 +282,14 @@ impl Child { }); } if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Child", wanted: 2, got: buf.remaining(), }); } let quux = Enum16::try_from(buf.get_u16()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Child", field: "quux", value: unknown_val as u64, @@ -305,7 +305,7 @@ impl Child { baz: parent.baz, }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -446,7 +446,7 @@ impl GrandChild { fn decode_partial(parent: &Child) -> Result { let mut buf: &[u8] = &parent.payload; if parent.bar() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandChild", field: "bar", expected: "Enum16::A", @@ -454,7 +454,7 @@ impl GrandChild { }); } if parent.quux() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandChild", field: "quux", expected: "Enum16::A", @@ -466,7 +466,7 @@ impl GrandChild { if buf.is_empty() { Ok(Self { payload, baz: parent.baz }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -611,7 +611,7 @@ impl GrandGrandChild { fn decode_partial(parent: &GrandChild) -> Result { let mut buf: &[u8] = &parent.payload; if parent.baz() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandGrandChild", field: "baz", expected: "Enum16::A", @@ -623,7 +623,7 @@ impl GrandGrandChild { if buf.is_empty() { Ok(Self { payload }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { diff --git a/pdl-compiler/tests/generated/rust/packet_decl_grand_children_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_grand_children_little_endian.rs index 39a573ec..d57b5ab4 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_grand_children_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_grand_children_little_endian.rs @@ -153,49 +153,49 @@ impl Packet for Parent { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let foo = Enum16::try_from(buf.get_u16_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "foo", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let bar = Enum16::try_from(buf.get_u16_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "bar", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let baz = Enum16::try_from(buf.get_u16_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "baz", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 1, got: buf.remaining(), @@ -203,7 +203,7 @@ impl Packet for Parent { } let payload_size = buf.get_u8() as usize; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: payload_size, got: buf.remaining(), @@ -274,7 +274,7 @@ impl Child { fn decode_partial(parent: &Parent) -> Result { let mut buf: &[u8] = &parent.payload; if parent.foo() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Child", field: "foo", expected: "Enum16::A", @@ -282,14 +282,14 @@ impl Child { }); } if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Child", wanted: 2, got: buf.remaining(), }); } let quux = Enum16::try_from(buf.get_u16_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Child", field: "quux", value: unknown_val as u64, @@ -305,7 +305,7 @@ impl Child { baz: parent.baz, }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -446,7 +446,7 @@ impl GrandChild { fn decode_partial(parent: &Child) -> Result { let mut buf: &[u8] = &parent.payload; if parent.bar() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandChild", field: "bar", expected: "Enum16::A", @@ -454,7 +454,7 @@ impl GrandChild { }); } if parent.quux() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandChild", field: "quux", expected: "Enum16::A", @@ -466,7 +466,7 @@ impl GrandChild { if buf.is_empty() { Ok(Self { payload, baz: parent.baz }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -611,7 +611,7 @@ impl GrandGrandChild { fn decode_partial(parent: &GrandChild) -> Result { let mut buf: &[u8] = &parent.payload; if parent.baz() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandGrandChild", field: "baz", expected: "Enum16::A", @@ -623,7 +623,7 @@ impl GrandGrandChild { if buf.is_empty() { Ok(Self { payload }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { diff --git a/pdl-compiler/tests/generated/rust/packet_decl_mask_scalar_value_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_mask_scalar_value_big_endian.rs index 7c242ba6..de85865a 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_mask_scalar_value_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_mask_scalar_value_big_endian.rs @@ -81,7 +81,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 4 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 4, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_mask_scalar_value_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_mask_scalar_value_little_endian.rs index bca8204c..d3afc5aa 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_mask_scalar_value_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_mask_scalar_value_little_endian.rs @@ -81,7 +81,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 4 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 4, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_mixed_scalars_enums_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_mixed_scalars_enums_big_endian.rs index 562427d7..b3c79284 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_mixed_scalars_enums_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_mixed_scalars_enums_big_endian.rs @@ -215,7 +215,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), @@ -223,7 +223,7 @@ impl Packet for Foo { } let chunk = buf.get_uint(3) as u32; let x = Enum7::try_from((chunk & 0x7f) as u8) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Foo", field: "x", value: unknown_val as u64, @@ -231,7 +231,7 @@ impl Packet for Foo { })?; let y = ((chunk >> 7) & 0x1f) as u8; let z = Enum9::try_from(((chunk >> 12) & 0x1ff) as u16) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Foo", field: "z", value: unknown_val as u64, diff --git a/pdl-compiler/tests/generated/rust/packet_decl_mixed_scalars_enums_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_mixed_scalars_enums_little_endian.rs index f8bd0886..3dbff976 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_mixed_scalars_enums_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_mixed_scalars_enums_little_endian.rs @@ -215,7 +215,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), @@ -223,7 +223,7 @@ impl Packet for Foo { } let chunk = buf.get_uint_le(3) as u32; let x = Enum7::try_from((chunk & 0x7f) as u8) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Foo", field: "x", value: unknown_val as u64, @@ -231,7 +231,7 @@ impl Packet for Foo { })?; let y = ((chunk >> 7) & 0x1f) as u8; let z = Enum9::try_from(((chunk >> 12) & 0x1ff) as u16) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Foo", field: "z", value: unknown_val as u64, diff --git a/pdl-compiler/tests/generated/rust/packet_decl_parent_with_alias_child_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_parent_with_alias_child_big_endian.rs index 2f7a09f2..9bbd5258 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_parent_with_alias_child_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_parent_with_alias_child_big_endian.rs @@ -142,14 +142,14 @@ impl Packet for Parent { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 1, got: buf.remaining(), }); } let v = Enum8::try_from(buf.get_u8()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "v", value: unknown_val as u64, @@ -217,7 +217,7 @@ impl AliasChild { if buf.is_empty() { Ok(Self { payload, v: parent.v }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -287,14 +287,14 @@ impl NormalChild { fn decode_partial(parent: &Parent) -> Result { let mut buf: &[u8] = &parent.payload; if parent.v() != Enum8::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "NormalChild", field: "v", expected: "Enum8::A", actual: format!("{:?}", parent.v()), }); } - if buf.is_empty() { Ok(Self {}) } else { Err(DecodeError::TrailingBytes) } + if buf.is_empty() { Ok(Self {}) } else { Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { Ok(()) @@ -380,14 +380,14 @@ impl NormalGrandChild1 { fn decode_partial(parent: &AliasChild) -> Result { let mut buf: &[u8] = &parent.payload; if parent.v() != Enum8::B { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "NormalGrandChild1", field: "v", expected: "Enum8::B", actual: format!("{:?}", parent.v()), }); } - if buf.is_empty() { Ok(Self {}) } else { Err(DecodeError::TrailingBytes) } + if buf.is_empty() { Ok(Self {}) } else { Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { Ok(()) @@ -475,7 +475,7 @@ impl NormalGrandChild2 { fn decode_partial(parent: &AliasChild) -> Result { let mut buf: &[u8] = &parent.payload; if parent.v() != Enum8::C { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "NormalGrandChild2", field: "v", expected: "Enum8::C", @@ -487,7 +487,7 @@ impl NormalGrandChild2 { if buf.is_empty() { Ok(Self { payload }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { diff --git a/pdl-compiler/tests/generated/rust/packet_decl_parent_with_alias_child_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_parent_with_alias_child_little_endian.rs index 2f7a09f2..9bbd5258 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_parent_with_alias_child_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_parent_with_alias_child_little_endian.rs @@ -142,14 +142,14 @@ impl Packet for Parent { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 1, got: buf.remaining(), }); } let v = Enum8::try_from(buf.get_u8()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "v", value: unknown_val as u64, @@ -217,7 +217,7 @@ impl AliasChild { if buf.is_empty() { Ok(Self { payload, v: parent.v }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -287,14 +287,14 @@ impl NormalChild { fn decode_partial(parent: &Parent) -> Result { let mut buf: &[u8] = &parent.payload; if parent.v() != Enum8::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "NormalChild", field: "v", expected: "Enum8::A", actual: format!("{:?}", parent.v()), }); } - if buf.is_empty() { Ok(Self {}) } else { Err(DecodeError::TrailingBytes) } + if buf.is_empty() { Ok(Self {}) } else { Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { Ok(()) @@ -380,14 +380,14 @@ impl NormalGrandChild1 { fn decode_partial(parent: &AliasChild) -> Result { let mut buf: &[u8] = &parent.payload; if parent.v() != Enum8::B { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "NormalGrandChild1", field: "v", expected: "Enum8::B", actual: format!("{:?}", parent.v()), }); } - if buf.is_empty() { Ok(Self {}) } else { Err(DecodeError::TrailingBytes) } + if buf.is_empty() { Ok(Self {}) } else { Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { Ok(()) @@ -475,7 +475,7 @@ impl NormalGrandChild2 { fn decode_partial(parent: &AliasChild) -> Result { let mut buf: &[u8] = &parent.payload; if parent.v() != Enum8::C { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "NormalGrandChild2", field: "v", expected: "Enum8::C", @@ -487,7 +487,7 @@ impl NormalGrandChild2 { if buf.is_empty() { Ok(Self { payload }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { diff --git a/pdl-compiler/tests/generated/rust/packet_decl_parent_with_no_payload_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_parent_with_no_payload_big_endian.rs index 7f3f9d47..578e2a0c 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_parent_with_no_payload_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_parent_with_no_payload_big_endian.rs @@ -126,14 +126,14 @@ impl Packet for Parent { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 1, got: buf.remaining(), }); } let v = Enum8::try_from(buf.get_u8()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "v", value: unknown_val as u64, @@ -170,7 +170,7 @@ impl TryFrom for Child { impl Child { fn decode_partial(parent: &Parent) -> Result { if parent.v() != Enum8::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Child", field: "v", expected: "Enum8::A", diff --git a/pdl-compiler/tests/generated/rust/packet_decl_parent_with_no_payload_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_parent_with_no_payload_little_endian.rs index 7f3f9d47..578e2a0c 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_parent_with_no_payload_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_parent_with_no_payload_little_endian.rs @@ -126,14 +126,14 @@ impl Packet for Parent { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 1, got: buf.remaining(), }); } let v = Enum8::try_from(buf.get_u8()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "v", value: unknown_val as u64, @@ -170,7 +170,7 @@ impl TryFrom for Child { impl Child { fn decode_partial(parent: &Parent) -> Result { if parent.v() != Enum8::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Child", field: "v", expected: "Enum8::A", diff --git a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_big_endian.rs index e12e8f3e..f39eba93 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_big_endian.rs @@ -61,7 +61,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_little_endian.rs index 4570ed95..20fd4781 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_little_endian.rs @@ -61,7 +61,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_terminal_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_terminal_big_endian.rs index c3e6d8b1..1ab155db 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_terminal_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_terminal_big_endian.rs @@ -61,7 +61,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), @@ -70,7 +70,7 @@ impl Packet for Foo { let payload = buf[..buf.len() - 3].to_vec(); buf.advance(payload.len()); if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_terminal_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_terminal_little_endian.rs index b1c39e2e..2c40a845 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_terminal_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_unknown_size_terminal_little_endian.rs @@ -61,7 +61,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), @@ -70,7 +70,7 @@ impl Packet for Foo { let payload = buf[..buf.len() - 3].to_vec(); buf.advance(payload.len()); if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_variable_size_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_variable_size_big_endian.rs index c7aede7b..4815c9f2 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_variable_size_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_variable_size_big_endian.rs @@ -68,7 +68,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -76,7 +76,7 @@ impl Packet for Foo { } let a = buf.get_u8(); if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -84,7 +84,7 @@ impl Packet for Foo { } let payload_size = buf.get_u8() as usize; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: payload_size, got: buf.remaining(), @@ -93,7 +93,7 @@ impl Packet for Foo { let payload = buf[..payload_size].to_vec(); buf.advance(payload_size); if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_variable_size_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_variable_size_little_endian.rs index 4b9616ef..973f5c22 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_payload_field_variable_size_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_payload_field_variable_size_little_endian.rs @@ -68,7 +68,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -76,7 +76,7 @@ impl Packet for Foo { } let a = buf.get_u8(); if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -84,7 +84,7 @@ impl Packet for Foo { } let payload_size = buf.get_u8() as usize; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: payload_size, got: buf.remaining(), @@ -93,7 +93,7 @@ impl Packet for Foo { let payload = buf[..payload_size].to_vec(); buf.advance(payload_size); if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_reserved_field_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_reserved_field_big_endian.rs index 42e365a4..3a1f36a2 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_reserved_field_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_reserved_field_big_endian.rs @@ -42,7 +42,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 5, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_reserved_field_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_reserved_field_little_endian.rs index 42e365a4..3a1f36a2 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_reserved_field_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_reserved_field_little_endian.rs @@ -42,7 +42,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 5 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 5, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_simple_scalars_big_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_simple_scalars_big_endian.rs index b175953b..965dc8e1 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_simple_scalars_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_simple_scalars_big_endian.rs @@ -66,7 +66,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -74,7 +74,7 @@ impl Packet for Foo { } let x = buf.get_u8(); if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), @@ -82,7 +82,7 @@ impl Packet for Foo { } let y = buf.get_u16(); if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/packet_decl_simple_scalars_little_endian.rs b/pdl-compiler/tests/generated/rust/packet_decl_simple_scalars_little_endian.rs index ab87026b..4d6fd584 100644 --- a/pdl-compiler/tests/generated/rust/packet_decl_simple_scalars_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/packet_decl_simple_scalars_little_endian.rs @@ -66,7 +66,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -74,7 +74,7 @@ impl Packet for Foo { } let x = buf.get_u8(); if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), @@ -82,7 +82,7 @@ impl Packet for Foo { } let y = buf.get_u16_le(); if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/payload_with_size_modifier_big_endian.rs b/pdl-compiler/tests/generated/rust/payload_with_size_modifier_big_endian.rs index e4d6f593..ae964644 100644 --- a/pdl-compiler/tests/generated/rust/payload_with_size_modifier_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/payload_with_size_modifier_big_endian.rs @@ -58,7 +58,7 @@ impl Packet for Test { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Test", wanted: 1, got: buf.remaining(), @@ -66,7 +66,7 @@ impl Packet for Test { } let payload_size = buf.get_u8() as usize; if payload_size < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Test", wanted: 1, got: payload_size, @@ -74,7 +74,7 @@ impl Packet for Test { } let payload_size = payload_size - 1; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Test", wanted: payload_size, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/payload_with_size_modifier_little_endian.rs b/pdl-compiler/tests/generated/rust/payload_with_size_modifier_little_endian.rs index e4d6f593..ae964644 100644 --- a/pdl-compiler/tests/generated/rust/payload_with_size_modifier_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/payload_with_size_modifier_little_endian.rs @@ -58,7 +58,7 @@ impl Packet for Test { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Test", wanted: 1, got: buf.remaining(), @@ -66,7 +66,7 @@ impl Packet for Test { } let payload_size = buf.get_u8() as usize; if payload_size < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Test", wanted: 1, got: payload_size, @@ -74,7 +74,7 @@ impl Packet for Test { } let payload_size = payload_size - 1; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Test", wanted: payload_size, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/reserved_identifier_big_endian.rs b/pdl-compiler/tests/generated/rust/reserved_identifier_big_endian.rs index f855ca1b..0c58f0bc 100644 --- a/pdl-compiler/tests/generated/rust/reserved_identifier_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/reserved_identifier_big_endian.rs @@ -48,7 +48,7 @@ impl Packet for Test { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Test", wanted: 1, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/reserved_identifier_little_endian.rs b/pdl-compiler/tests/generated/rust/reserved_identifier_little_endian.rs index f855ca1b..0c58f0bc 100644 --- a/pdl-compiler/tests/generated/rust/reserved_identifier_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/reserved_identifier_little_endian.rs @@ -48,7 +48,7 @@ impl Packet for Test { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Test", wanted: 1, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/struct_decl_child_structs_big_endian.rs b/pdl-compiler/tests/generated/rust/struct_decl_child_structs_big_endian.rs index 2d97e819..3449ff30 100644 --- a/pdl-compiler/tests/generated/rust/struct_decl_child_structs_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/struct_decl_child_structs_big_endian.rs @@ -145,7 +145,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -153,21 +153,21 @@ impl Packet for Foo { } let a = buf.get_u8(); if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), }); } let b = Enum16::try_from(buf.get_u16()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Foo", field: "b", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -175,7 +175,7 @@ impl Packet for Foo { } let payload_size = buf.get_u8() as usize; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: payload_size, got: buf.remaining(), @@ -227,7 +227,7 @@ impl Bar { fn decode_partial(parent: &Foo) -> Result { let mut buf: &[u8] = &parent.payload; if parent.a() != 100 { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Bar", field: "a", expected: "100", @@ -235,7 +235,7 @@ impl Bar { }); } if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -245,7 +245,7 @@ impl Bar { if buf.is_empty() { Ok(Self { x, b: parent.b }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -333,7 +333,7 @@ impl Baz { fn decode_partial(parent: &Foo) -> Result { let mut buf: &[u8] = &parent.payload; if parent.b() != Enum16::B { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Baz", field: "b", expected: "Enum16::B", @@ -341,7 +341,7 @@ impl Baz { }); } if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Baz", wanted: 2, got: buf.remaining(), @@ -351,7 +351,7 @@ impl Baz { if buf.is_empty() { Ok(Self { y, a: parent.a }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { diff --git a/pdl-compiler/tests/generated/rust/struct_decl_child_structs_little_endian.rs b/pdl-compiler/tests/generated/rust/struct_decl_child_structs_little_endian.rs index 1d45c0db..a37730d8 100644 --- a/pdl-compiler/tests/generated/rust/struct_decl_child_structs_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/struct_decl_child_structs_little_endian.rs @@ -145,7 +145,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -153,21 +153,21 @@ impl Packet for Foo { } let a = buf.get_u8(); if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), }); } let b = Enum16::try_from(buf.get_u16_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Foo", field: "b", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 1, got: buf.remaining(), @@ -175,7 +175,7 @@ impl Packet for Foo { } let payload_size = buf.get_u8() as usize; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: payload_size, got: buf.remaining(), @@ -227,7 +227,7 @@ impl Bar { fn decode_partial(parent: &Foo) -> Result { let mut buf: &[u8] = &parent.payload; if parent.a() != 100 { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Bar", field: "a", expected: "100", @@ -235,7 +235,7 @@ impl Bar { }); } if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Bar", wanted: 1, got: buf.remaining(), @@ -245,7 +245,7 @@ impl Bar { if buf.is_empty() { Ok(Self { x, b: parent.b }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -333,7 +333,7 @@ impl Baz { fn decode_partial(parent: &Foo) -> Result { let mut buf: &[u8] = &parent.payload; if parent.b() != Enum16::B { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Baz", field: "b", expected: "Enum16::B", @@ -341,7 +341,7 @@ impl Baz { }); } if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Baz", wanted: 2, got: buf.remaining(), @@ -351,7 +351,7 @@ impl Baz { if buf.is_empty() { Ok(Self { y, a: parent.a }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { diff --git a/pdl-compiler/tests/generated/rust/struct_decl_complex_scalars_big_endian.rs b/pdl-compiler/tests/generated/rust/struct_decl_complex_scalars_big_endian.rs index b8325359..addac7ca 100644 --- a/pdl-compiler/tests/generated/rust/struct_decl_complex_scalars_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/struct_decl_complex_scalars_big_endian.rs @@ -120,7 +120,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), @@ -131,7 +131,7 @@ impl Packet for Foo { let b = (chunk >> 3) as u8; let c = ((chunk >> 11) & 0x1f) as u8; if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), @@ -139,7 +139,7 @@ impl Packet for Foo { } let d = buf.get_uint(3) as u32; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/struct_decl_complex_scalars_little_endian.rs b/pdl-compiler/tests/generated/rust/struct_decl_complex_scalars_little_endian.rs index a2f37877..c681c422 100644 --- a/pdl-compiler/tests/generated/rust/struct_decl_complex_scalars_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/struct_decl_complex_scalars_little_endian.rs @@ -120,7 +120,7 @@ impl Packet for Foo { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), @@ -131,7 +131,7 @@ impl Packet for Foo { let b = (chunk >> 3) as u8; let c = ((chunk >> 11) & 0x1f) as u8; if buf.remaining() < 3 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 3, got: buf.remaining(), @@ -139,7 +139,7 @@ impl Packet for Foo { } let d = buf.get_uint_le(3) as u32; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Foo", wanted: 2, got: buf.remaining(), diff --git a/pdl-compiler/tests/generated/rust/struct_decl_grand_children_big_endian.rs b/pdl-compiler/tests/generated/rust/struct_decl_grand_children_big_endian.rs index f757ea58..290c7ffe 100644 --- a/pdl-compiler/tests/generated/rust/struct_decl_grand_children_big_endian.rs +++ b/pdl-compiler/tests/generated/rust/struct_decl_grand_children_big_endian.rs @@ -153,49 +153,49 @@ impl Packet for Parent { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let foo = Enum16::try_from(buf.get_u16()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "foo", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let bar = Enum16::try_from(buf.get_u16()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "bar", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let baz = Enum16::try_from(buf.get_u16()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "baz", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 1, got: buf.remaining(), @@ -203,7 +203,7 @@ impl Packet for Parent { } let payload_size = buf.get_u8() as usize; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: payload_size, got: buf.remaining(), @@ -275,7 +275,7 @@ impl Child { fn decode_partial(parent: &Parent) -> Result { let mut buf: &[u8] = &parent.payload; if parent.foo() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Child", field: "foo", expected: "Enum16::A", @@ -283,14 +283,14 @@ impl Child { }); } if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Child", wanted: 2, got: buf.remaining(), }); } let quux = Enum16::try_from(buf.get_u16()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Child", field: "quux", value: unknown_val as u64, @@ -307,7 +307,7 @@ impl Child { baz: parent.baz, }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -448,7 +448,7 @@ impl GrandChild { fn decode_partial(parent: &Child) -> Result { let mut buf: &[u8] = &parent.payload; if parent.bar() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandChild", field: "bar", expected: "Enum16::A", @@ -456,7 +456,7 @@ impl GrandChild { }); } if parent.quux() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandChild", field: "quux", expected: "Enum16::A", @@ -469,7 +469,7 @@ impl GrandChild { if buf.is_empty() { Ok(Self { payload, baz: parent.baz }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -614,7 +614,7 @@ impl GrandGrandChild { fn decode_partial(parent: &GrandChild) -> Result { let mut buf: &[u8] = &parent.payload; if parent.baz() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandGrandChild", field: "baz", expected: "Enum16::A", @@ -627,7 +627,7 @@ impl GrandGrandChild { if buf.is_empty() { Ok(Self { payload }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { diff --git a/pdl-compiler/tests/generated/rust/struct_decl_grand_children_little_endian.rs b/pdl-compiler/tests/generated/rust/struct_decl_grand_children_little_endian.rs index 8ed64a5d..5cac600b 100644 --- a/pdl-compiler/tests/generated/rust/struct_decl_grand_children_little_endian.rs +++ b/pdl-compiler/tests/generated/rust/struct_decl_grand_children_little_endian.rs @@ -153,49 +153,49 @@ impl Packet for Parent { } fn decode(mut buf: &[u8]) -> Result<(Self, &[u8]), DecodeError> { if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let foo = Enum16::try_from(buf.get_u16_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "foo", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let bar = Enum16::try_from(buf.get_u16_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "bar", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 2, got: buf.remaining(), }); } let baz = Enum16::try_from(buf.get_u16_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Parent", field: "baz", value: unknown_val as u64, type_: "Enum16", })?; if buf.remaining() < 1 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: 1, got: buf.remaining(), @@ -203,7 +203,7 @@ impl Packet for Parent { } let payload_size = buf.get_u8() as usize; if buf.remaining() < payload_size { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Parent", wanted: payload_size, got: buf.remaining(), @@ -275,7 +275,7 @@ impl Child { fn decode_partial(parent: &Parent) -> Result { let mut buf: &[u8] = &parent.payload; if parent.foo() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "Child", field: "foo", expected: "Enum16::A", @@ -283,14 +283,14 @@ impl Child { }); } if buf.remaining() < 2 { - return Err(DecodeError::InvalidLengthError { + return Err(DecodeError::LengthError { obj: "Child", wanted: 2, got: buf.remaining(), }); } let quux = Enum16::try_from(buf.get_u16_le()) - .map_err(|unknown_val| DecodeError::InvalidEnumValueError { + .map_err(|unknown_val| DecodeError::EnumValueError { obj: "Child", field: "quux", value: unknown_val as u64, @@ -307,7 +307,7 @@ impl Child { baz: parent.baz, }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -448,7 +448,7 @@ impl GrandChild { fn decode_partial(parent: &Child) -> Result { let mut buf: &[u8] = &parent.payload; if parent.bar() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandChild", field: "bar", expected: "Enum16::A", @@ -456,7 +456,7 @@ impl GrandChild { }); } if parent.quux() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandChild", field: "quux", expected: "Enum16::A", @@ -469,7 +469,7 @@ impl GrandChild { if buf.is_empty() { Ok(Self { payload, baz: parent.baz }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { @@ -614,7 +614,7 @@ impl GrandGrandChild { fn decode_partial(parent: &GrandChild) -> Result { let mut buf: &[u8] = &parent.payload; if parent.baz() != Enum16::A { - return Err(DecodeError::InvalidFieldValue { + return Err(DecodeError::ConstraintValueError { packet: "GrandGrandChild", field: "baz", expected: "Enum16::A", @@ -627,7 +627,7 @@ impl GrandGrandChild { if buf.is_empty() { Ok(Self { payload }) } else { - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) } } pub fn encode_partial(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> { diff --git a/pdl-runtime/src/lib.rs b/pdl-runtime/src/lib.rs index c2b8cdce..77e76b77 100644 --- a/pdl-runtime/src/lib.rs +++ b/pdl-runtime/src/lib.rs @@ -19,36 +19,28 @@ use bytes::{BufMut, Bytes, BytesMut}; /// Type of parsing errors. #[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)] pub enum DecodeError { - #[error("packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: &'static str, value: u64 }, + /// This error case is generated in places where an unwrap call would be used. + /// All occurences in the generated code actually correspond to unreachable + /// statements, but this error is generated instead to keep the code unwrap free. + #[error("unwrap error")] + UnwrapError, #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, + FixedValueError { expected: u64, actual: u64 }, #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: &'static str, wanted: usize, got: usize }, + LengthError { obj: &'static str, wanted: usize, got: usize }, #[error("array size ({array} bytes) is not a multiple of the element size ({element} bytes)")] - InvalidArraySize { array: usize, element: usize }, - #[error("Due to size restrictions a struct could not be parsed.")] - ImpossibleStructError, + ArraySizeError { array: usize, element: usize }, #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { - obj: &'static str, - field: &'static str, - value: u64, - type_: &'static str, - }, + EnumValueError { obj: &'static str, field: &'static str, value: u64, type_: &'static str }, #[error("invalid field {packet}::{field} value, {expected} != {actual}")] - InvalidFieldValue { + ConstraintValueError { packet: &'static str, field: &'static str, expected: &'static str, actual: String, }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, #[error("packet has trailing bytes")] - TrailingBytes, + TrailingBytesError, #[error("packet has trailing bytes inside {obj}.{field} array")] TrailingBytesInArray { obj: &'static str, field: &'static str }, } @@ -102,7 +94,7 @@ pub trait Packet: Sized { /// Returns an error if unparsed bytes remain at the end of the input slice. fn decode_full(buf: &[u8]) -> Result { let (packet, remaining) = Self::decode(buf)?; - if remaining.is_empty() { Ok(packet) } else { Err(DecodeError::TrailingBytes) } + if remaining.is_empty() { Ok(packet) } else { Err(DecodeError::TrailingBytesError) } } /// Return the length of the encoded packet. diff --git a/pdl-tests/tests/convert.rs b/pdl-tests/tests/convert.rs index 698cfea4..b91e594f 100644 --- a/pdl-tests/tests/convert.rs +++ b/pdl-tests/tests/convert.rs @@ -60,43 +60,43 @@ mod convert { // Invalid constraint value. assert!(matches!( Child2::try_from(Parent { a: 1, payload: vec![42, 0, 0] }), - Err(DecodeError::InvalidFieldValue { .. }) + Err(DecodeError::ConstraintValueError { .. }) )); assert!(matches!( GrandChild1::try_from(Parent { a: 2, payload: vec![42, 0, 0] }), - Err(DecodeError::InvalidFieldValue { .. }) + Err(DecodeError::ConstraintValueError { .. }) )); assert!(matches!( GrandChild1::try_from(Parent { a: 1, payload: vec![43, 0, 0] }), - Err(DecodeError::InvalidFieldValue { .. }) + Err(DecodeError::ConstraintValueError { .. }) )); // Payload contains too many bytes. assert!(matches!( Child2::try_from(Parent { a: 2, payload: vec![42, 2, 3, 4] }), - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) )); assert!(matches!( GrandChild1::try_from(Parent { a: 1, payload: vec![42, 0, 1, 2] }), - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) )); assert!(matches!( GrandChild1::try_from(Child1 { x: 42, payload: vec![0, 1, 2] }), - Err(DecodeError::TrailingBytes) + Err(DecodeError::TrailingBytesError) )); // Payload contains too few bytes. assert!(matches!( Child1::try_from(Parent { a: 1, payload: vec![] }), - Err(DecodeError::InvalidLengthError { .. }) + Err(DecodeError::LengthError { .. }) )); assert!(matches!( GrandChild1::try_from(Parent { a: 1, payload: vec![42, 0] }), - Err(DecodeError::InvalidLengthError { .. }) + Err(DecodeError::LengthError { .. }) )); assert!(matches!( GrandChild1::try_from(Child1 { x: 42, payload: vec![0] }), - Err(DecodeError::InvalidLengthError { .. }) + Err(DecodeError::LengthError { .. }) )); } diff --git a/pdl-tests/tests/specialize.rs b/pdl-tests/tests/specialize.rs index 24a91039..4fe4f867 100644 --- a/pdl-tests/tests/specialize.rs +++ b/pdl-tests/tests/specialize.rs @@ -45,13 +45,13 @@ mod child_determined_by_constraint { // a valid child. let parent = Parent::decode_full(&[1, 2, 3]).unwrap(); assert_eq!(parent.a, 1); - assert!(matches!(parent.specialize(), Err(DecodeError::TrailingBytes))); + assert!(matches!(parent.specialize(), Err(DecodeError::TrailingBytesError))); // Payload contains too few bytes; specialize fails to produce // a valid child. let parent = Parent::decode_full(&[1]).unwrap(); assert_eq!(parent.a, 1); - assert!(matches!(parent.specialize(), Err(DecodeError::InvalidLengthError { .. }))); + assert!(matches!(parent.specialize(), Err(DecodeError::LengthError { .. }))); } #[test] @@ -65,13 +65,13 @@ mod child_determined_by_constraint { // a valid child. let parent = Parent::decode_full(&[2, 2, 3, 4]).unwrap(); assert_eq!(parent.a, 2); - assert!(matches!(parent.specialize(), Err(DecodeError::TrailingBytes))); + assert!(matches!(parent.specialize(), Err(DecodeError::TrailingBytesError))); // Payload contains too few bytes; specialize fails to produce // a valid child. let parent = Parent::decode_full(&[2, 0]).unwrap(); assert_eq!(parent.a, 2); - assert!(matches!(parent.specialize(), Err(DecodeError::InvalidLengthError { .. }))); + assert!(matches!(parent.specialize(), Err(DecodeError::LengthError { .. }))); } #[test] @@ -118,13 +118,13 @@ mod grandchild_determined_by_constraint { // a valid child. let child = Child::decode_full(&[1, 1, 2, 3]).unwrap(); assert_eq!(child.b, 1); - assert!(matches!(child.specialize(), Err(DecodeError::TrailingBytes))); + assert!(matches!(child.specialize(), Err(DecodeError::TrailingBytesError))); // Payload contains too few bytes; specialize fails to produce // a valid child. let child = Child::decode_full(&[1, 1]).unwrap(); assert_eq!(child.b, 1); - assert!(matches!(child.specialize(), Err(DecodeError::InvalidLengthError { .. }))); + assert!(matches!(child.specialize(), Err(DecodeError::LengthError { .. }))); } #[test] @@ -138,13 +138,13 @@ mod grandchild_determined_by_constraint { // a valid child. let child = Child::decode_full(&[1, 2, 2, 3, 4]).unwrap(); assert_eq!(child.b, 2); - assert!(matches!(child.specialize(), Err(DecodeError::TrailingBytes))); + assert!(matches!(child.specialize(), Err(DecodeError::TrailingBytesError))); // Payload contains too few bytes; specialize fails to produce // a valid child. let child = Child::decode_full(&[1, 2, 0]).unwrap(); assert_eq!(child.b, 2); - assert!(matches!(child.specialize(), Err(DecodeError::InvalidLengthError { .. }))); + assert!(matches!(child.specialize(), Err(DecodeError::LengthError { .. }))); } #[test] @@ -321,13 +321,13 @@ mod child_determined_by_child_constraint { // a valid child. let parent = Parent::decode_full(&[1, 2, 3, 4]).unwrap(); assert_eq!(parent.a, 1); - assert!(matches!(parent.specialize(), Err(DecodeError::InvalidArraySize { .. }))); + assert!(matches!(parent.specialize(), Err(DecodeError::ArraySizeError { .. }))); // Payload contains too few bytes; specialize fails to produce // a valid child. let parent = Parent::decode_full(&[1, 2]).unwrap(); assert_eq!(parent.a, 1); - assert!(matches!(parent.specialize(), Err(DecodeError::InvalidArraySize { .. }))); + assert!(matches!(parent.specialize(), Err(DecodeError::ArraySizeError { .. }))); } #[test]