1#[cfg(any(feature = "read", feature = "write"))]
21pub mod field;
22pub mod field_number;
23pub mod tag;
24pub mod varint;
25pub mod wire_format;
26
27#[cfg(feature = "write")]
28pub use self::field::WriteExtProtobuf;
29#[cfg(any(feature = "read", feature = "write"))]
30pub use self::field::{Field, FieldValue};
31#[cfg(feature = "read")]
32pub use self::field::{ProtobufFieldIterator, ReadExtProtobuf};
33pub use self::field_number::FieldNumber;
34pub use self::tag::{ReadExtTag, Tag, read_tag};
35pub use self::varint::{IteratorExtVarint, ReadExtVarint, Varint, WriteExtVarint};
36pub use self::wire_format::{MAX_FIELD_NUMBER, MAX_MESSAGE_SIZE, MIN_FIELD_NUMBER, WireType};
37
38use ::thiserror::Error;
39
40#[derive(Error, Debug)]
42pub enum ProtobufError {
43 #[error("Field number {value} is out of valid range [1, 536_870_911]")]
44 FieldNumberOutOfRange { value: String },
45
46 #[error("Invalid wire type: {value} (must be 0-5)")]
47 InvalidWireType { value: u8 },
48
49 #[error("Varint value {value} is out of range for target type: {target_type}")]
50 VarintDowncastOutOfRange {
51 value: u64,
52 target_type: &'static str,
53 },
54
55 #[error("Failed to downcast field value to expected type: {expected_type}")]
56 FieldTypeDowncastError { expected_type: String },
57
58 #[error("Malformed tag: field_number={field_number}, wire_type={wire_type}")]
59 MalformedTag { field_number: u32, wire_type: u8 },
60
61 #[error("Unexpected EOF while parsing field")]
62 UnexpectedEof,
63
64 #[error("I/O error: {0}")]
65 IoError(#[from] ::std::io::Error),
66}
67
68pub type Result<T> = ::std::result::Result<T, ProtobufError>;