pub enum ByteOrder {
BigEndian,
LittleEndian,
BigEndianSwap,
LittleEndianSwap,
BigEndian16,
LittleEndian16,
}Expand description
Unified byte/word order representation for 16/32/64-bit values.
§Example
use voltage_modbus::ByteOrder;
let order = ByteOrder::from_str("CDAB").unwrap();
assert_eq!(order, ByteOrder::BigEndianSwap);
assert!(order.has_word_swap());Variants§
BigEndian
Big-endian: ABCD (most significant byte first)
Network byte order, used in most protocols. Example: 0x12345678 → [0x12, 0x34, 0x56, 0x78]
LittleEndian
Little-endian: DCBA (least significant byte first)
Intel x86 native byte order. Example: 0x12345678 → [0x78, 0x56, 0x34, 0x12]
BigEndianSwap
Big-endian with swapped words: CDAB
Common in Modbus and some PLCs. Words are big-endian but swapped. Example: 0x12345678 → [0x56, 0x78, 0x12, 0x34]
LittleEndianSwap
Little-endian with swapped words: BADC
Rare, but exists in some devices. Example: 0x12345678 → [0x34, 0x12, 0x78, 0x56]
BigEndian16
16-bit big-endian: AB
For 16-bit values only. Example: 0x1234 → [0x12, 0x34]
LittleEndian16
16-bit little-endian: BA
For 16-bit values only. Example: 0x1234 → [0x34, 0x12]
Implementations§
Source§impl ByteOrder
impl ByteOrder
Sourcepub fn from_str(s: &str) -> Option<Self>
pub fn from_str(s: &str) -> Option<Self>
Convert from legacy string formats.
Supports various common string representations:
- “ABCD”, “AB-CD” → BigEndian
- “DCBA”, “DC-BA” → LittleEndian
- “CDAB”, “CD-AB” → BigEndianSwap
- “BADC”, “BA-DC” → LittleEndianSwap
- “BE”, “BIG_ENDIAN” → BigEndian
- “LE”, “LITTLE_ENDIAN” → LittleEndian
- “AB” → BigEndian16
- “BA” → LittleEndian16
Sourcepub fn is_16bit_only(&self) -> bool
pub fn is_16bit_only(&self) -> bool
Check if this is a 16-bit only byte order.
Sourcepub fn is_big_endian(&self) -> bool
pub fn is_big_endian(&self) -> bool
Check if this is a big-endian variant.
Sourcepub fn is_little_endian(&self) -> bool
pub fn is_little_endian(&self) -> bool
Check if this is a little-endian variant.
Sourcepub fn has_word_swap(&self) -> bool
pub fn has_word_swap(&self) -> bool
Check if words are swapped (for 32/64-bit values).