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
68
69
70
71
72
73
74
75
76
77
78
79
//! Module related to how data is interpreted, such as its layout and endianness.
use size_of;
use crateCodec;
use crate::;
/// The Decode trait defines how a type is deserialized or decoded from a
/// slice or chunk of bytes. It provides a way to translate raw byte sequences
/// back into meaningful data in a structured manner.
///
/// # Safety and Alignment
///
/// The Decode trait prioritizes safety and correctness over speed when it comes to
/// decoding data. It intentionally avoids using ptr::read_unaligned due to potential
/// alignment issues. Correctly handling alignment is an important part of preventing
/// undefined behavior, which is a key goal of the abio crate.
///
/// # Endian-Aware Decoding
///
/// [`Decode`] leverages the [`Codec`] type to provide access to the
/// [`Endian`][crate::endian::Endian] and Endian traits to decode byte streams in an
/// endian-aware manner. It ensures the proper interpretation of data according to
/// the specific byte order serialization type.
///
/// # Default Implementations
///
/// By default, Decode is implemented for types defined within the abio crate,
/// including its "aligned" integer types. These default implementations allow for
/// immediate use of Decode in a majority of cases where endian-aware, safe decoding
/// is required.