BinaryLayout API

The BinaryLayout module provides classes which are able to describe binary structures and access bit-level data from the binary sources using the layouts as a templates.

BinaryLayout class

A BinaryLayout is a description of a binary structure. If you are familiar with c-struct statement, its the same concept. The BinaryLayout allows a description of individual fields within a structured piece of data. Its like a stamp that can be applied to data to extract data with a specified structure.

BitField class

A BitField is what retrieves or stores the data in memory according the the description found in a BinaryLayout introduced above. Its called a bit-field, because you can access data using BitFields up to a single bit resolution within the data structure. Just like c-structures can do as well. You can also access all the java primitives and arrays.

ArrayField class

An ArrayField uses a BinaryLayout definition to access arrays instead of bits from a data-source. You can define a SequenceLayout, a binary layout of a sequence of elements aka an array, and access that part of data as arrays using an ArrayField.

BitFields only work on primitive numbers and bits, while ArrayFields work on sequences/arrays of java primitives.

Data sources

BitFields and ArrayFields perform their operations (set or get) on a data source. A data source which contains or will contain the data is operated on by these binary fields.

Almost any data-source can be used, and in the future an extension mechanism maybe added to allow more. Here is a list of currently allowed data-sources.

  • A java primitive: byte, short, int, long, float or a double

  • A java array: byte[], short[], int[] or long[]

  • A java nio: java.nio.ByteBuffer

  • A java foreign memory function (JEP-424): jdk.incubator.foreign.MemorySegment

  • A jNet buffers module: DataBuffer

Example 1: simple BinaryLayout and BitField variables: