javaproject-panamajava-ffm

Using Foreign Function and Memory API with bit offsets instead of BitSet


I would like to define a MemoryLayout from the Panama API in JDK 22 with bit offsets. ValueLayouts like ValueLayout.JAVA_BYTE seem to only be usable with a byte granularity, which doesn't fit my use case.

I wanted to use the Panama API to load a byte[] and access specific values according to a scheme, that for example defines that there is a value between bit 3 and 6 and another value between bit 7 and 9, and so on. When checking the JDK 18 incubator documentation of MemoryLayout there are functions referring bitOffset instead of byteOffset.

Currently I am using a BitSet to interpret the scheme, but I was looking forward to using a more direct approach. Is this not supported anymore or am I missing something?


Solution

  • No, the JDK 22 API does not offer any functions supporting individual by-bit offsets.