mcnbt/byte_order.rs
1use num_traits::ToBytes;
2
3/// Java Edition uses big endian and Bedrock Edition uses little endian.
4#[derive(Debug, Copy, Clone, PartialEq)]
5pub enum ByteOrder {
6 BigEndian,
7 LittleEndian,
8}
9
10impl ByteOrder {
11 pub fn bytes(&self, num: impl ToBytes) -> Vec<u8> {
12 match self {
13 Self::BigEndian => num.to_be_bytes().as_ref().to_owned(),
14 Self::LittleEndian => num.to_le_bytes().as_ref().to_owned(),
15 }
16 }
17}