From 4c15582c75ebefef8ef5fa4879a606154e2f8fa6 Mon Sep 17 00:00:00 2001 From: Henri Chataing Date: Thu, 7 Sep 2023 09:11:50 -0700 Subject: [PATCH] Move all preamble definitions to a new pdl-runtime crate The pdl-runtime crate will hold all common definitions for the generated modules. Currently it defines - Error: type of parsing errors - Packet: trait for top-level packets - Private: wrapper for opaque scalar fields --- Cargo.toml | 1 + doc/rust-generated-code-guide.rst | 7 ++- pdl-compiler/src/backends/rust/preamble.rs | 41 +------------ .../custom_field_declaration_big_endian.rs | 39 +----------- .../custom_field_declaration_little_endian.rs | 39 +----------- .../generated/enum_declaration_big_endian.rs | 39 +----------- .../enum_declaration_little_endian.rs | 39 +----------- ...packet_decl_24bit_enum_array_big_endian.rs | 39 +----------- ...ket_decl_24bit_enum_array_little_endian.rs | 39 +----------- .../packet_decl_24bit_enum_big_endian.rs | 39 +----------- .../packet_decl_24bit_enum_little_endian.rs | 39 +----------- ...cket_decl_24bit_scalar_array_big_endian.rs | 39 +----------- ...t_decl_24bit_scalar_array_little_endian.rs | 39 +----------- .../packet_decl_24bit_scalar_big_endian.rs | 39 +----------- .../packet_decl_24bit_scalar_little_endian.rs | 39 +----------- ...packet_decl_64bit_enum_array_big_endian.rs | 39 +----------- ...ket_decl_64bit_enum_array_little_endian.rs | 39 +----------- .../packet_decl_64bit_enum_big_endian.rs | 39 +----------- .../packet_decl_64bit_enum_little_endian.rs | 39 +----------- ...cket_decl_64bit_scalar_array_big_endian.rs | 39 +----------- ...t_decl_64bit_scalar_array_little_endian.rs | 39 +----------- .../packet_decl_64bit_scalar_big_endian.rs | 39 +----------- .../packet_decl_64bit_scalar_little_endian.rs | 39 +----------- .../packet_decl_8bit_enum_array_big_endian.rs | 39 +----------- ...cket_decl_8bit_enum_array_little_endian.rs | 39 +----------- .../packet_decl_8bit_enum_big_endian.rs | 39 +----------- .../packet_decl_8bit_enum_little_endian.rs | 39 +----------- ...acket_decl_8bit_scalar_array_big_endian.rs | 39 +----------- ...et_decl_8bit_scalar_array_little_endian.rs | 39 +----------- .../packet_decl_8bit_scalar_big_endian.rs | 39 +----------- .../packet_decl_8bit_scalar_little_endian.rs | 39 +----------- ...ket_decl_array_dynamic_count_big_endian.rs | 39 +----------- ..._decl_array_dynamic_count_little_endian.rs | 39 +----------- ...cket_decl_array_dynamic_size_big_endian.rs | 39 +----------- ...t_decl_array_dynamic_size_little_endian.rs | 39 +----------- ..._element_width_dynamic_count_big_endian.rs | 39 +----------- ...ement_width_dynamic_count_little_endian.rs | 39 +----------- ...n_element_width_dynamic_size_big_endian.rs | 39 +----------- ...lement_width_dynamic_size_little_endian.rs | 39 +----------- ...cket_decl_array_with_padding_big_endian.rs | 39 +----------- ...t_decl_array_with_padding_little_endian.rs | 39 +----------- .../packet_decl_child_packets_big_endian.rs | 39 +----------- ...packet_decl_child_packets_little_endian.rs | 39 +----------- .../packet_decl_complex_scalars_big_endian.rs | 39 +----------- ...cket_decl_complex_scalars_little_endian.rs | 39 +----------- .../packet_decl_custom_field_big_endian.rs | 39 +----------- .../packet_decl_custom_field_little_endian.rs | 39 +----------- .../generated/packet_decl_empty_big_endian.rs | 39 +----------- .../packet_decl_empty_little_endian.rs | 39 +----------- ...packet_decl_fixed_enum_field_big_endian.rs | 39 +----------- ...ket_decl_fixed_enum_field_little_endian.rs | 39 +----------- ...cket_decl_fixed_scalar_field_big_endian.rs | 39 +----------- ...t_decl_fixed_scalar_field_little_endian.rs | 39 +----------- .../packet_decl_grand_children_big_endian.rs | 39 +----------- ...acket_decl_grand_children_little_endian.rs | 39 +----------- ...acket_decl_mask_scalar_value_big_endian.rs | 39 +----------- ...et_decl_mask_scalar_value_little_endian.rs | 39 +----------- ...ket_decl_mixed_scalars_enums_big_endian.rs | 39 +----------- ..._decl_mixed_scalars_enums_little_endian.rs | 39 +----------- ...decl_parent_with_alias_child_big_endian.rs | 39 +----------- ...l_parent_with_alias_child_little_endian.rs | 39 +----------- ..._decl_parent_with_no_payload_big_endian.rs | 39 +----------- ...cl_parent_with_no_payload_little_endian.rs | 39 +----------- ...l_payload_field_unknown_size_big_endian.rs | 39 +----------- ...ayload_field_unknown_size_little_endian.rs | 39 +----------- ..._field_unknown_size_terminal_big_endian.rs | 39 +----------- ...eld_unknown_size_terminal_little_endian.rs | 39 +----------- ..._payload_field_variable_size_big_endian.rs | 39 +----------- ...yload_field_variable_size_little_endian.rs | 39 +----------- .../packet_decl_reserved_field_big_endian.rs | 39 +----------- ...acket_decl_reserved_field_little_endian.rs | 39 +----------- .../packet_decl_simple_scalars_big_endian.rs | 39 +----------- ...acket_decl_simple_scalars_little_endian.rs | 39 +----------- pdl-compiler/tests/generated/preamble.rs | 39 +----------- .../reserved_identifier_big_endian.rs | 39 +----------- .../reserved_identifier_little_endian.rs | 39 +----------- .../struct_decl_complex_scalars_big_endian.rs | 39 +----------- ...ruct_decl_complex_scalars_little_endian.rs | 39 +----------- pdl-derive/Cargo.toml | 2 +- pdl-derive/tests/examples.rs | 2 + pdl-runtime/Cargo.toml | 19 ++++++ pdl-runtime/src/lib.rs | 59 +++++++++++++++++++ 82 files changed, 162 insertions(+), 2894 deletions(-) create mode 100644 pdl-runtime/Cargo.toml create mode 100644 pdl-runtime/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 44a6907..414943b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,4 +2,5 @@ members = [ "pdl-compiler", "pdl-derive", + "pdl-runtime", ] diff --git a/doc/rust-generated-code-guide.rst b/doc/rust-generated-code-guide.rst index f7bc2f7..579921d 100644 --- a/doc/rust-generated-code-guide.rst +++ b/doc/rust-generated-code-guide.rst @@ -9,7 +9,8 @@ using the `pdl` proc_macro attribute. Example usage: .. sourcecode:: rust - use pdl_derive::pdl + use pdl_derive::pdl; + use pdl_runtime::*; #[pdl("my-protocol.pdl")] mod my_protocol { @@ -32,8 +33,8 @@ Language bindings This section contains the generated rust bindings for language constructs that are stabilized. -Preamble -^^^^^^^^ +Runtime +^^^^^^^ Private prevents users from creating arbitrary scalar values in situations where the value needs to be validated. Users can freely deref the value, but only the diff --git a/pdl-compiler/src/backends/rust/preamble.rs b/pdl-compiler/src/backends/rust/preamble.rs index ce8b742..92356f7 100644 --- a/pdl-compiler/src/backends/rust/preamble.rs +++ b/pdl-compiler/src/backends/rust/preamble.rs @@ -55,48 +55,9 @@ pub fn generate(path: &Path) -> proc_macro2::TokenStream { use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; - use thiserror::Error; + use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; - - /// Private prevents users from creating arbitrary scalar values - /// in situations where the value needs to be validated. - /// Users can freely deref the value, but only the backend - /// may create it. - #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] - pub struct Private(T); - - impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } - } - - #[derive(Debug, Error)] - pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, - } - - pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; - } } } diff --git a/pdl-compiler/tests/generated/custom_field_declaration_big_endian.rs b/pdl-compiler/tests/generated/custom_field_declaration_big_endian.rs index 8046f5a..e2cd295 100644 --- a/pdl-compiler/tests/generated/custom_field_declaration_big_endian.rs +++ b/pdl-compiler/tests/generated/custom_field_declaration_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(from = "u32", into = "u32"))] diff --git a/pdl-compiler/tests/generated/custom_field_declaration_little_endian.rs b/pdl-compiler/tests/generated/custom_field_declaration_little_endian.rs index 8046f5a..e2cd295 100644 --- a/pdl-compiler/tests/generated/custom_field_declaration_little_endian.rs +++ b/pdl-compiler/tests/generated/custom_field_declaration_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(from = "u32", into = "u32"))] diff --git a/pdl-compiler/tests/generated/enum_declaration_big_endian.rs b/pdl-compiler/tests/generated/enum_declaration_big_endian.rs index ffc4725..8986680 100644 --- a/pdl-compiler/tests/generated/enum_declaration_big_endian.rs +++ b/pdl-compiler/tests/generated/enum_declaration_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/enum_declaration_little_endian.rs b/pdl-compiler/tests/generated/enum_declaration_little_endian.rs index ffc4725..8986680 100644 --- a/pdl-compiler/tests/generated/enum_declaration_little_endian.rs +++ b/pdl-compiler/tests/generated/enum_declaration_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_24bit_enum_array_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_24bit_enum_array_big_endian.rs index 7717d7a..a67c1af 100644 --- a/pdl-compiler/tests/generated/packet_decl_24bit_enum_array_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_24bit_enum_array_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_24bit_enum_array_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_24bit_enum_array_little_endian.rs index 2fb9a9c..ff01127 100644 --- a/pdl-compiler/tests/generated/packet_decl_24bit_enum_array_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_24bit_enum_array_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_24bit_enum_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_24bit_enum_big_endian.rs index 272e52d..70403ef 100644 --- a/pdl-compiler/tests/generated/packet_decl_24bit_enum_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_24bit_enum_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_24bit_enum_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_24bit_enum_little_endian.rs index 278336c..b7918ec 100644 --- a/pdl-compiler/tests/generated/packet_decl_24bit_enum_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_24bit_enum_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_24bit_scalar_array_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_24bit_scalar_array_big_endian.rs index 193c5e5..10a741a 100644 --- a/pdl-compiler/tests/generated/packet_decl_24bit_scalar_array_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_24bit_scalar_array_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_24bit_scalar_array_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_24bit_scalar_array_little_endian.rs index fafba2c..0727057 100644 --- a/pdl-compiler/tests/generated/packet_decl_24bit_scalar_array_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_24bit_scalar_array_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_24bit_scalar_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_24bit_scalar_big_endian.rs index 15e76b0..62e3358 100644 --- a/pdl-compiler/tests/generated/packet_decl_24bit_scalar_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_24bit_scalar_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_24bit_scalar_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_24bit_scalar_little_endian.rs index 77ede78..1be3c88 100644 --- a/pdl-compiler/tests/generated/packet_decl_24bit_scalar_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_24bit_scalar_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_64bit_enum_array_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_64bit_enum_array_big_endian.rs index caeba78..1e44edb 100644 --- a/pdl-compiler/tests/generated/packet_decl_64bit_enum_array_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_64bit_enum_array_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_64bit_enum_array_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_64bit_enum_array_little_endian.rs index 2a698b8..261ed1d 100644 --- a/pdl-compiler/tests/generated/packet_decl_64bit_enum_array_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_64bit_enum_array_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_64bit_enum_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_64bit_enum_big_endian.rs index f29c654..9a5fdb7 100644 --- a/pdl-compiler/tests/generated/packet_decl_64bit_enum_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_64bit_enum_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_64bit_enum_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_64bit_enum_little_endian.rs index 0bc5a12..e5bc122 100644 --- a/pdl-compiler/tests/generated/packet_decl_64bit_enum_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_64bit_enum_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_64bit_scalar_array_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_64bit_scalar_array_big_endian.rs index b4816d6..8318a46 100644 --- a/pdl-compiler/tests/generated/packet_decl_64bit_scalar_array_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_64bit_scalar_array_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_64bit_scalar_array_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_64bit_scalar_array_little_endian.rs index b6c3423..fa1f71e 100644 --- a/pdl-compiler/tests/generated/packet_decl_64bit_scalar_array_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_64bit_scalar_array_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_64bit_scalar_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_64bit_scalar_big_endian.rs index 1cda594..076fb20 100644 --- a/pdl-compiler/tests/generated/packet_decl_64bit_scalar_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_64bit_scalar_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_64bit_scalar_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_64bit_scalar_little_endian.rs index 10e62d4..b76199f 100644 --- a/pdl-compiler/tests/generated/packet_decl_64bit_scalar_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_64bit_scalar_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_8bit_enum_array_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_8bit_enum_array_big_endian.rs index f36f1ba..a21f8ca 100644 --- a/pdl-compiler/tests/generated/packet_decl_8bit_enum_array_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_8bit_enum_array_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_8bit_enum_array_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_8bit_enum_array_little_endian.rs index f36f1ba..a21f8ca 100644 --- a/pdl-compiler/tests/generated/packet_decl_8bit_enum_array_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_8bit_enum_array_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_8bit_enum_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_8bit_enum_big_endian.rs index bccdaeb..66faf4f 100644 --- a/pdl-compiler/tests/generated/packet_decl_8bit_enum_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_8bit_enum_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_8bit_enum_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_8bit_enum_little_endian.rs index bccdaeb..66faf4f 100644 --- a/pdl-compiler/tests/generated/packet_decl_8bit_enum_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_8bit_enum_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_8bit_scalar_array_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_8bit_scalar_array_big_endian.rs index 518a775..dbc8980 100644 --- a/pdl-compiler/tests/generated/packet_decl_8bit_scalar_array_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_8bit_scalar_array_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_8bit_scalar_array_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_8bit_scalar_array_little_endian.rs index 518a775..dbc8980 100644 --- a/pdl-compiler/tests/generated/packet_decl_8bit_scalar_array_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_8bit_scalar_array_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_8bit_scalar_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_8bit_scalar_big_endian.rs index 19b51a9..7eb26bd 100644 --- a/pdl-compiler/tests/generated/packet_decl_8bit_scalar_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_8bit_scalar_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_8bit_scalar_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_8bit_scalar_little_endian.rs index 19b51a9..7eb26bd 100644 --- a/pdl-compiler/tests/generated/packet_decl_8bit_scalar_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_8bit_scalar_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_array_dynamic_count_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_array_dynamic_count_big_endian.rs index e1887d6..b24e60b 100644 --- a/pdl-compiler/tests/generated/packet_decl_array_dynamic_count_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_array_dynamic_count_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_array_dynamic_count_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_array_dynamic_count_little_endian.rs index a7fcdd1..29aa7bc 100644 --- a/pdl-compiler/tests/generated/packet_decl_array_dynamic_count_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_array_dynamic_count_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_array_dynamic_size_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_array_dynamic_size_big_endian.rs index 934b21f..901adbd 100644 --- a/pdl-compiler/tests/generated/packet_decl_array_dynamic_size_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_array_dynamic_size_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_array_dynamic_size_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_array_dynamic_size_little_endian.rs index d56c554..5b2e8e3 100644 --- a/pdl-compiler/tests/generated/packet_decl_array_dynamic_size_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_array_dynamic_size_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_count_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_count_big_endian.rs index 0ddc911..d52e402 100644 --- a/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_count_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_count_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Foo { diff --git a/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_count_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_count_little_endian.rs index 86a85e4..6338480 100644 --- a/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_count_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_count_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Foo { diff --git a/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_size_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_size_big_endian.rs index bd67530..fb9205d 100644 --- a/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_size_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_size_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Foo { diff --git a/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_size_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_size_little_endian.rs index c41a8d4..adef94a 100644 --- a/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_size_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_array_unknown_element_width_dynamic_size_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Foo { diff --git a/pdl-compiler/tests/generated/packet_decl_array_with_padding_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_array_with_padding_big_endian.rs index e45dc03..4ce57b1 100644 --- a/pdl-compiler/tests/generated/packet_decl_array_with_padding_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_array_with_padding_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Foo { diff --git a/pdl-compiler/tests/generated/packet_decl_array_with_padding_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_array_with_padding_little_endian.rs index bd1aae0..6adbf8e 100644 --- a/pdl-compiler/tests/generated/packet_decl_array_with_padding_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_array_with_padding_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Foo { diff --git a/pdl-compiler/tests/generated/packet_decl_child_packets_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_child_packets_big_endian.rs index 8b3e05d..884aaff 100644 --- a/pdl-compiler/tests/generated/packet_decl_child_packets_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_child_packets_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_child_packets_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_child_packets_little_endian.rs index 8a464b2..f3645d3 100644 --- a/pdl-compiler/tests/generated/packet_decl_child_packets_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_child_packets_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_complex_scalars_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_complex_scalars_big_endian.rs index be97361..c96156e 100644 --- a/pdl-compiler/tests/generated/packet_decl_complex_scalars_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_complex_scalars_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_complex_scalars_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_complex_scalars_little_endian.rs index 7ccee61..3d794e4 100644 --- a/pdl-compiler/tests/generated/packet_decl_complex_scalars_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_complex_scalars_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_custom_field_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_custom_field_big_endian.rs index 7b7dc9a..a956187 100644 --- a/pdl-compiler/tests/generated/packet_decl_custom_field_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_custom_field_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(try_from = "u32", into = "u32"))] diff --git a/pdl-compiler/tests/generated/packet_decl_custom_field_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_custom_field_little_endian.rs index d805403..481ae12 100644 --- a/pdl-compiler/tests/generated/packet_decl_custom_field_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_custom_field_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(try_from = "u32", into = "u32"))] diff --git a/pdl-compiler/tests/generated/packet_decl_empty_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_empty_big_endian.rs index eb0b173..87cffeb 100644 --- a/pdl-compiler/tests/generated/packet_decl_empty_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_empty_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData {} diff --git a/pdl-compiler/tests/generated/packet_decl_empty_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_empty_little_endian.rs index eb0b173..87cffeb 100644 --- a/pdl-compiler/tests/generated/packet_decl_empty_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_empty_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData {} diff --git a/pdl-compiler/tests/generated/packet_decl_fixed_enum_field_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_fixed_enum_field_big_endian.rs index 5c780ad..31307fe 100644 --- a/pdl-compiler/tests/generated/packet_decl_fixed_enum_field_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_fixed_enum_field_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_fixed_enum_field_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_fixed_enum_field_little_endian.rs index 45486c5..c4511d7 100644 --- a/pdl-compiler/tests/generated/packet_decl_fixed_enum_field_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_fixed_enum_field_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_fixed_scalar_field_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_fixed_scalar_field_big_endian.rs index 4d0ecb5..ed70df0 100644 --- a/pdl-compiler/tests/generated/packet_decl_fixed_scalar_field_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_fixed_scalar_field_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_fixed_scalar_field_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_fixed_scalar_field_little_endian.rs index 5d4ba13..8156167 100644 --- a/pdl-compiler/tests/generated/packet_decl_fixed_scalar_field_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_fixed_scalar_field_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_grand_children_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_grand_children_big_endian.rs index f1a2cac..2b4e88c 100644 --- a/pdl-compiler/tests/generated/packet_decl_grand_children_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_grand_children_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_grand_children_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_grand_children_little_endian.rs index 66fa76a..38ffa3d 100644 --- a/pdl-compiler/tests/generated/packet_decl_grand_children_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_grand_children_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_mask_scalar_value_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_mask_scalar_value_big_endian.rs index 47f7a70..4bc7eee 100644 --- a/pdl-compiler/tests/generated/packet_decl_mask_scalar_value_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_mask_scalar_value_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_mask_scalar_value_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_mask_scalar_value_little_endian.rs index 95f6c9d..420fdc5 100644 --- a/pdl-compiler/tests/generated/packet_decl_mask_scalar_value_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_mask_scalar_value_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_mixed_scalars_enums_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_mixed_scalars_enums_big_endian.rs index 7dcf2e6..4ce954c 100644 --- a/pdl-compiler/tests/generated/packet_decl_mixed_scalars_enums_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_mixed_scalars_enums_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_mixed_scalars_enums_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_mixed_scalars_enums_little_endian.rs index 667dab3..1293eba 100644 --- a/pdl-compiler/tests/generated/packet_decl_mixed_scalars_enums_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_mixed_scalars_enums_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_parent_with_alias_child_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_parent_with_alias_child_big_endian.rs index 785c0ee..aa244b1 100644 --- a/pdl-compiler/tests/generated/packet_decl_parent_with_alias_child_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_parent_with_alias_child_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_parent_with_alias_child_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_parent_with_alias_child_little_endian.rs index 785c0ee..aa244b1 100644 --- a/pdl-compiler/tests/generated/packet_decl_parent_with_alias_child_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_parent_with_alias_child_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_parent_with_no_payload_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_parent_with_no_payload_big_endian.rs index 82c45c5..4421543 100644 --- a/pdl-compiler/tests/generated/packet_decl_parent_with_no_payload_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_parent_with_no_payload_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_parent_with_no_payload_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_parent_with_no_payload_little_endian.rs index 82c45c5..4421543 100644 --- a/pdl-compiler/tests/generated/packet_decl_parent_with_no_payload_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_parent_with_no_payload_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[repr(u64)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_big_endian.rs index be55b05..588b337 100644 --- a/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum FooDataChild { diff --git a/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_little_endian.rs index bc20979..dc1a1b2 100644 --- a/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum FooDataChild { diff --git a/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_terminal_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_terminal_big_endian.rs index a8af260..a736393 100644 --- a/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_terminal_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_terminal_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum FooDataChild { diff --git a/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_terminal_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_terminal_little_endian.rs index c615757..011b231 100644 --- a/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_terminal_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_payload_field_unknown_size_terminal_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum FooDataChild { diff --git a/pdl-compiler/tests/generated/packet_decl_payload_field_variable_size_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_payload_field_variable_size_big_endian.rs index ea6f7bf..2e0bf8e 100644 --- a/pdl-compiler/tests/generated/packet_decl_payload_field_variable_size_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_payload_field_variable_size_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum FooDataChild { diff --git a/pdl-compiler/tests/generated/packet_decl_payload_field_variable_size_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_payload_field_variable_size_little_endian.rs index f2932f0..35f3881 100644 --- a/pdl-compiler/tests/generated/packet_decl_payload_field_variable_size_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_payload_field_variable_size_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum FooDataChild { diff --git a/pdl-compiler/tests/generated/packet_decl_reserved_field_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_reserved_field_big_endian.rs index 6d2a01e..7b964e1 100644 --- a/pdl-compiler/tests/generated/packet_decl_reserved_field_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_reserved_field_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData {} diff --git a/pdl-compiler/tests/generated/packet_decl_reserved_field_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_reserved_field_little_endian.rs index 6d2a01e..7b964e1 100644 --- a/pdl-compiler/tests/generated/packet_decl_reserved_field_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_reserved_field_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData {} diff --git a/pdl-compiler/tests/generated/packet_decl_simple_scalars_big_endian.rs b/pdl-compiler/tests/generated/packet_decl_simple_scalars_big_endian.rs index f2048d9..88eac0d 100644 --- a/pdl-compiler/tests/generated/packet_decl_simple_scalars_big_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_simple_scalars_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/packet_decl_simple_scalars_little_endian.rs b/pdl-compiler/tests/generated/packet_decl_simple_scalars_little_endian.rs index 16f01f7..30bc6a1 100644 --- a/pdl-compiler/tests/generated/packet_decl_simple_scalars_little_endian.rs +++ b/pdl-compiler/tests/generated/packet_decl_simple_scalars_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FooData { diff --git a/pdl-compiler/tests/generated/preamble.rs b/pdl-compiler/tests/generated/preamble.rs index e3e9772..a97324e 100644 --- a/pdl-compiler/tests/generated/preamble.rs +++ b/pdl-compiler/tests/generated/preamble.rs @@ -4,42 +4,5 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} diff --git a/pdl-compiler/tests/generated/reserved_identifier_big_endian.rs b/pdl-compiler/tests/generated/reserved_identifier_big_endian.rs index 1f13532..032b29e 100644 --- a/pdl-compiler/tests/generated/reserved_identifier_big_endian.rs +++ b/pdl-compiler/tests/generated/reserved_identifier_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TestData { diff --git a/pdl-compiler/tests/generated/reserved_identifier_little_endian.rs b/pdl-compiler/tests/generated/reserved_identifier_little_endian.rs index 1f13532..032b29e 100644 --- a/pdl-compiler/tests/generated/reserved_identifier_little_endian.rs +++ b/pdl-compiler/tests/generated/reserved_identifier_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TestData { diff --git a/pdl-compiler/tests/generated/struct_decl_complex_scalars_big_endian.rs b/pdl-compiler/tests/generated/struct_decl_complex_scalars_big_endian.rs index a8de9c9..356d000 100644 --- a/pdl-compiler/tests/generated/struct_decl_complex_scalars_big_endian.rs +++ b/pdl-compiler/tests/generated/struct_decl_complex_scalars_big_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Foo { diff --git a/pdl-compiler/tests/generated/struct_decl_complex_scalars_little_endian.rs b/pdl-compiler/tests/generated/struct_decl_complex_scalars_little_endian.rs index e0741f7..a59711d 100644 --- a/pdl-compiler/tests/generated/struct_decl_complex_scalars_little_endian.rs +++ b/pdl-compiler/tests/generated/struct_decl_complex_scalars_little_endian.rs @@ -4,45 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::convert::{TryFrom, TryInto}; use std::cell::Cell; use std::fmt; -use thiserror::Error; +use pdl_runtime::{Error, Packet, Private}; type Result = std::result::Result; -/// Private prevents users from creating arbitrary scalar values -/// in situations where the value needs to be validated. -/// Users can freely deref the value, but only the backend -/// may create it. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Private(T); -impl std::ops::Deref for Private { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -#[derive(Debug, Error)] -pub enum Error { - #[error("Packet parsing failed")] - InvalidPacketError, - #[error("{field} was {value:x}, which is not known")] - ConstraintOutOfBounds { field: String, value: u64 }, - #[error("Got {actual:x}, expected {expected:x}")] - InvalidFixedValue { expected: u64, actual: u64 }, - #[error("when parsing {obj} needed length of {wanted} but got {got}")] - InvalidLengthError { obj: String, 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, - #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] - InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, - #[error("expected child {expected}, got {actual}")] - InvalidChildError { expected: &'static str, actual: String }, -} -pub trait Packet { - fn to_bytes(self) -> Bytes; - fn to_vec(self) -> Vec; -} #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Foo { diff --git a/pdl-derive/Cargo.toml b/pdl-derive/Cargo.toml index 421f483..2e56e38 100644 --- a/pdl-derive/Cargo.toml +++ b/pdl-derive/Cargo.toml @@ -28,5 +28,5 @@ syn = {version = "2.0.29", features = ["full"]} termcolor = "1.2.0" [dev-dependencies] +pdl-runtime = {path = "../pdl-runtime", version = "0.1.7"} bytes = "1.4.0" -thiserror = "1.0.47" diff --git a/pdl-derive/tests/examples.rs b/pdl-derive/tests/examples.rs index ddd0455..48674d7 100644 --- a/pdl-derive/tests/examples.rs +++ b/pdl-derive/tests/examples.rs @@ -22,6 +22,8 @@ fn test_pcap() { mod pcap {} use pcap::*; + use pdl_runtime::Packet; + let pcap_file = PcapFileBuilder { header: PcapHeader { version_major: 1, diff --git a/pdl-runtime/Cargo.toml b/pdl-runtime/Cargo.toml new file mode 100644 index 0000000..5994859 --- /dev/null +++ b/pdl-runtime/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "pdl-runtime" +version = "0.1.7" +edition = "2021" +description = "PDL's runtime library" +repository = "https://github.com/google/pdl/" +license = "Apache-2.0" +readme = "../README.md" +keywords = ["pdl", "parser", "serializer", "grammar"] +authors = [ + "Henri Chataing ", + "David de Jesus Duarte ", + "Martin Geisler " +] +categories = ["parsing"] + +[dependencies] +bytes = "1.4.0" +thiserror = "1.0.47" diff --git a/pdl-runtime/src/lib.rs b/pdl-runtime/src/lib.rs new file mode 100644 index 0000000..1f31d1a --- /dev/null +++ b/pdl-runtime/src/lib.rs @@ -0,0 +1,59 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Helper definitions used used by the generated Rust backend. + +use bytes::Bytes; +use thiserror::Error; + +/// Type of parsing errors. +#[derive(Debug, Error)] +pub enum Error { + #[error("Packet parsing failed")] + InvalidPacketError, + #[error("{field} was {value:x}, which is not known")] + ConstraintOutOfBounds { field: String, value: u64 }, + #[error("Got {actual:x}, expected {expected:x}")] + InvalidFixedValue { expected: u64, actual: u64 }, + #[error("when parsing {obj} needed length of {wanted} but got {got}")] + InvalidLengthError { obj: String, 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, + #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")] + InvalidEnumValueError { obj: String, field: String, value: u64, type_: String }, + #[error("expected child {expected}, got {actual}")] + InvalidChildError { expected: &'static str, actual: String }, +} + +/// Trait implemented for all toplevel packet declarations. +pub trait Packet { + fn to_bytes(self) -> Bytes; + fn to_vec(self) -> Vec; +} + +/// Private prevents users from creating arbitrary scalar values +/// in situations where the value needs to be validated. +/// Users can freely deref the value, but only the backend +/// may create it. +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct Private(T); + +impl std::ops::Deref for Private { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } +}