A practical guide to endianness (byte order) and bit order, how they are applied in FastProto, and how to avoid common mistakes.
@BoolType).@DefaultByteOrder(...), @DefaultBitOrder(...).byteOrder only where the spec deviates from the default.bitOrder that matches the spec (LSB_0 or MSB_0).byteOrder > Class @DefaultByteOrder > Global default (LITTLE).UInt8, Int8, Ascii/Char) are unaffected.@Checksum.byteOrder affects how the checksum value is stored/read; it does not change the calculation over the data range. See Checksum / CRC.LSB_0 (bit 0 is the least‑significant bit of the byte).@DefaultBitOrder(...) or per field via bitOrder.@BoolType(byteOffset = x, bitOffset = y, bitOrder = ...).import org.indunet.fastproto.*;
import org.indunet.fastproto.annotation.*;
@DefaultByteOrder(ByteOrder.BIG)
public class Example {
@UInt16Type(offset = 0) // BIG (class default)
int a;
@UInt16Type(offset = 2, byteOrder = ByteOrder.LITTLE) // field override
int b;
}import org.indunet.fastproto.*;
import org.indunet.fastproto.annotation.*;
@DefaultBitOrder(BitOrder.MSB_0)
public class Flags {
@BoolType(byteOffset = 0, bitOffset = 0) // topmost bit is bit 0
boolean valid;
@BoolType(byteOffset = 0, bitOffset = 7) // least‑significant bit in MSB_0
boolean lowFlag;
}import org.indunet.fastproto.*;
import org.indunet.fastproto.annotation.*;
@DefaultByteOrder(ByteOrder.LITTLE)
@DefaultBitOrder(BitOrder.LSB_0)
public class BitFields {
// Use lengthRef to determine bit width dynamically; logical start bitOffset=6, spans bytes
@BitFieldType(offset = 0, bitOffset = 6, lengthRef = "$width", byteOrder = ByteOrder.LITTLE, bitOrder = BitOrder.LSB_0)
int value;
@UInt8Type(offset = 2)
int width; // Provides the length; must be declared before use
}import org.indunet.fastproto.*;
import org.indunet.fastproto.annotation.*;
public class Vector {
@UInt32ArrayType(offset = 0, length = 3, byteOrder = {ByteOrder.LITTLE})
long[] points; // each element is 4 bytes, stored little‑endian
}byteOrder only affects the stored checksum field’s byte order, not the CRC computation over data bytes.