Build codecov Codacy JetBrains License

Why FastProto?

Annotation-Driven
Map byte layouts to Java fields with clear, type-safe annotations.
Checksums Built-in
Single-annotation @Checksum with CRC8/16/32/64, LRC, XOR.
Byte & Bit Order
Per-field or global endianness and bit order.
Fast APIs
Encode/decode with or without annotations, low overhead.

Key Features

  • Annotation-Driven mapping
  • Broad Type Support (incl. unsigned)
  • Flexible addressing (reverse offsets)
  • Configurable Byte Order
  • Custom Formulas (lambda/class)
  • Checksum/CRC: CRC8/16/32/64, LRC, XOR
  • Easy APIs with/without annotations

Install

Maven

<dependency>
  <groupId>org.indunet</groupId>
  <artifactId>fastproto</artifactId>
  <version>3.12.0</version>
</dependency>

Gradle

implementation "org.indunet:fastproto:3.12.0"

Quick Example

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);

Checksum/CRC

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;
}