Operate on byte buffers directly when you cannot or do not want to decorate classes with annotations.
FastProto offers two complementary ways to work without annotations:
byte[]byteOffset + bitOffsetByteOrder; chain API variants have overloads toobyte[] bytes = ...; // input buffer
class Obj { Boolean f1; Integer f2; Integer f3; }
Obj obj = FastProto.decode(bytes)
.readBool("f1", 0, 0)
.readInt8("f2", 1)
.readInt16("f3", 2)
.mapTo(Obj.class);import org.indunet.fastproto.util.DecodeUtils;
import org.indunet.fastproto.ByteOrder;
byte[] bytes = ...;
boolean f1 = DecodeUtils.readBool(bytes, 0, 0); // bit 0 in byte 0
int f2 = DecodeUtils.readInt8(bytes, 1);
int f3 = DecodeUtils.readInt16(bytes, 2, ByteOrder.LITTLE);
long u32 = DecodeUtils.readUInt32(bytes, 4, ByteOrder.BIG);import org.indunet.fastproto.ByteOrder;
byte[] out = FastProto.create(12)
.writeInt8(0, 1)
.writeUInt16(2, 3, 4) // two u16 values at 2..5
.writeUInt32(6, ByteOrder.BIG, 256) // u32 at 6..9 (big‑endian)
.get();import org.indunet.fastproto.util.EncodeUtils;
import org.indunet.fastproto.ByteOrder;
byte[] out = new byte[12];
EncodeUtils.writeInt8(out, 0, 1);
EncodeUtils.writeUInt16(out, 2, 3); // little‑endian default
EncodeUtils.writeUInt32(out, 6, ByteOrder.BIG, 256);import org.indunet.fastproto.annotation.Checksum;
import org.indunet.fastproto.checksum.ChecksumUtils;
// Compute CRC16 over bytes[0..4] and place it at offset 5..6 (little‑endian) manually
byte[] buf = new byte[]{0x31,0x32,0x33,0x34,0x35,0,0};
long crc = ChecksumUtils.calculate(buf, 0, 5, Checksum.Type.CRC16);
EncodeUtils.writeUInt16(buf, 5, ByteOrder.LITTLE, (int) crc);FastProto.encode(object, totalLength) or FastProto.create(totalLength) to safely reference trailing regions by absolute offsetsByteOrder for multi‑byte values to match your spec