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
/// The byte order trait.
pub use byteorder::ByteOrder;
/// Little Endian.
pub type LE = byteorder::LittleEndian;
/// Big Endian.
pub type BE = byteorder::BigEndian;
/// Native Endian.
pub type NE = byteorder::NativeEndian;
/// Opposing Endian.
#[cfg(target_endian = "little")]
pub type OP = byteorder::BigEndian;
#[cfg(target_endian = "big")]
pub type OP = byteorder::LittleEndian;

// These are runtime endian detection items since byteorder
// has had an outstanding ticket to add such things for several
// years and as such seems they will not be added.

// It is needed here because we 'try' to work with local endian
// but have to know how to flip things at runtime when dealing
// with non-native endian.

/// Runtime endianess values.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub enum Endian {
    /// Little endian.
    Little,
    /// Big endian.
    Big,
}

// Runtime native endian.

/// The runtime native endian.
#[cfg(target_endian = "little")]
pub const NATIVE_ENDIAN: Endian = Endian::Little;
/// The runtime native endian.
#[cfg(target_endian = "big")]
pub const NATIVE_ENDIAN: Endian = Endian::Big;

// Runtime opposiing endian.

/// The runtime opposing endian.
#[cfg(target_endian = "little")]
pub const OPPOSING_ENDIAN: Endian = Endian::Big;
/// The runtime opposing endian.
#[cfg(target_endian = "big")]
pub const OPPOSING_ENDIAN: Endian = Endian::Little;