@Checksum
with CRC8/16/32/64, LRC, XOR.Maven
<dependency>
<groupId>org.indunet</groupId>
<artifactId>fastproto</artifactId>
<version>3.12.0</version>
</dependency>
Gradle
implementation "org.indunet:fastproto:3.12.0"
import org.indunet.fastproto.annotation.*;
public class Weather {
@UInt8Type(offset = 0) int id;
@TimeType(offset = 2) java.sql.Timestamp time;
@UInt16Type(offset = 10) int humidity;
@Int16Type(offset = 12) int temperature;
@UInt32Type(offset = 14) long pressure;
@BoolType(byteOffset = 18, bitOffset = 0) boolean deviceValid;
}
// Decode / Encode
byte[] bytes = ...;
Weather w = org.indunet.fastproto.FastProto.decode(bytes, Weather.class);
byte[] out = org.indunet.fastproto.FastProto.encode(w, 20);
import org.indunet.fastproto.annotation.Checksum;
import org.indunet.fastproto.ByteOrder;
public class Packet {
@UInt8Type(offset = 0) int b1;
@UInt8Type(offset = 1) int b2;
@UInt8Type(offset = 2) int b3;
@UInt8Type(offset = 3) int b4;
@UInt8Type(offset = 4) int b5;
// Compute over [0,5), write CRC16 LE at 5..6
@Checksum(start = 0, length = 5, offset = 5,
type = Checksum.Type.CRC16,
byteOrder = ByteOrder.LITTLE)
int crc16;
}