1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::decode::MAXIMUM_VARIANT_DEPTH;
use crate::message::{MessageHeaderError, MessageHeaderField, MessageHeaderFieldError};
use crate::value::{
BusError, ErrorError, InterfaceError, MemberError, ObjectPathError, StructError, Type,
TypeError, MAXIMUM_ARRAY_LENGTH,
};
use std::str::Utf8Error;
use thiserror::Error;
pub type DecodeResult<T> = Result<T, DecodeError>;
#[derive(Debug, PartialEq, Error)]
pub enum DecodeError {
#[error("Not enough bytes to decode: got {0} offset {1}")]
NotEnoughBytes(usize, usize),
#[error("Boolean value only can be 0 or 1: {0}")]
InvalidBoolean(u32),
#[error("Could not decode string as UTF-8: {0}")]
Utf8Error(#[from] Utf8Error),
#[error("Last byte is not null: {0}")]
StringNotNull(u8),
#[error("Could not decode Bus: {0}")]
BusError(#[from] BusError),
#[error("Could not decode ObjectPath: {0}")]
ObjectPathError(#[from] ObjectPathError),
#[error("Could not decode Interface: {0}")]
InterfaceError(#[from] InterfaceError),
#[error("Could not decode Member: {0}")]
MemberError(#[from] MemberError),
#[error("Could not decode Error: {0}")]
ErrorError(#[from] ErrorError),
#[error("Could not decode Signature: {0}")]
SignatureError(#[from] TypeError),
#[error("Could not decode Struct: {0}")]
StructError(#[from] StructError),
#[error("Padding is not zero: {0}")]
Padding(u8),
#[error("Array length is too big: {MAXIMUM_ARRAY_LENGTH} < {0}")]
ArrayTooBig(u32),
#[error("Array is invalid: got {0} excepted {1}")]
ArrayInvalidLength(usize, usize),
#[error("Could not decode the endianness: {0}")]
Endianness(u8),
#[error("Could not decode MessageType: {0}")]
MessageType(u8),
#[error("Could not decode MessageFlags: {0}")]
MessageFlags(u8),
#[error("The MessageHeaderField {0} exists twice in the header")]
MessageHeaderFieldDouble(MessageHeaderField),
#[error("The body length is zero, but there is a body signature '{0:?}'")]
BodyLengthZero(Vec<Type>),
#[error("The body signature is missing, but there body length 0 != {0}")]
BodySignatureMissing(u32),
#[error("Not enough FDs: got {0} offset {1}")]
NotEnoughFds(usize, usize),
#[error("Could not the body: expected {0} got {1}")]
BodyLength(usize, usize),
#[error("Could not decode MessageHeader: {0}")]
MessageHeaderError(#[from] MessageHeaderError),
#[error("Could not decode MessageHeaderField: {0}")]
MessageHeaderFieldError(#[from] MessageHeaderFieldError),
#[error("Integer overflows occours: {0} + {1}")]
IntegerOverflow(usize, usize),
#[error("Variant depth is too big: {MAXIMUM_VARIANT_DEPTH} < {0}")]
VariantDepth(u8),
}