Yeah this sort of work isn't Java's strong suite. A lot of it's sort of like programming old-school C with oven mitts. It'll get a bit better with the Foreign Memory API which is in the JEP pipe.
But a very bare bones example might look something like
class MdrLayout {
static final int FOO_OFFSET = 0;
static final int BAR_OFFSET = 4;
static final int BAZ_OFFSET = 12;
static final int ENTRY_SIZE = 13;
}
class MyDataRecord {
int idx = Integer.MIN_VALUE;
ByteBuffer buffer = null;
MyDataRecord() { }
void movePointer(ByteBuffer buffer, int idx) {
this.buffer = buffer;
this.idx = idx;
}
int foo() { return buffer.getInt(ENTRY_SIZE * idx + FOO_OFFSET); }
long bar() { return buffer.getLong(ENTRY_SIZE * idx + BAR_OFFSET); }
byte baz() { return buffer.get(ENTRY_SIZE * idx + BAZ_OFFSET); }
// may have operators like reset(), next() or skip() as well
}
or
class MyDataRecord2 {
final ByteBuffer buffer;
MyDataRecord2(ByteBuffer buffer) { this.buffer = buffer; }
int foo(int idx) { return buffer.getInt(ENTRY_SIZE * idx + FOO_OFFSET); }
long bar(int idx) { return buffer.getLong(ENTRY_SIZE * idx + BAR_OFFSET); }
byte baz(int idx) { return buffer.get(ENTRY_SIZE * idx + BAZ_OFFSET); }
}