| #![rustfmt::skip] |
| /// @generated rust packets from foo.pdl. |
| use bytes::{Buf, BufMut, Bytes, BytesMut}; |
| use std::convert::{TryFrom, TryInto}; |
| use std::cell::Cell; |
| use std::fmt; |
| use thiserror::Error; |
| type Result<T> = std::result::Result<T, Error>; |
| /// 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>(T); |
| impl<T> std::ops::Deref for Private<T> { |
| 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<u8>; |
| } |