Generate BE, LE, and configured byte order accessor methods

Motivation:
As previously stated, we wish to have configurable byte order on our buffers.

Modification:
Update the generator to produce 3 variants of accessors; for configured byte order, for BE and for LE.
Also run the generator and include the new code in the commit.

Result:
We now have configurable byte order for our buffers, and explicit accessors for both BE and LE.
This commit is contained in:
Chris Vest 2020-10-06 16:30:49 +02:00
parent 8941fab5fa
commit 4147d7d51d
4 changed files with 3093 additions and 310 deletions

View File

@ -20,6 +20,7 @@ import jdk.incubator.foreign.MemorySegment;
import java.nio.ByteOrder;
import static jdk.incubator.foreign.MemoryAccess.getByteAtOffset_BE;
import static jdk.incubator.foreign.MemoryAccess.getByteAtOffset_LE;
import static jdk.incubator.foreign.MemoryAccess.getCharAtOffset_BE;
import static jdk.incubator.foreign.MemoryAccess.getCharAtOffset_LE;
import static jdk.incubator.foreign.MemoryAccess.getDoubleAtOffset_BE;
@ -136,7 +137,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public byte readByte() {
checkRead(roff, Byte.BYTES);
byte value = getByteAtOffset_BE(seg, roff);
byte value = (isBigEndian? getByteAtOffset_BE(seg, roff) : getByteAtOffset_LE(seg, roff));
roff += Byte.BYTES;
return value;
}
@ -144,13 +145,13 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public byte readByte(int roff) {
checkRead(roff, Byte.BYTES);
return getByteAtOffset_BE(seg, roff);
return (isBigEndian? getByteAtOffset_BE(seg, roff) : getByteAtOffset_LE(seg, roff));
}
@Override
public int readUnsignedByte() {
checkRead(roff, Byte.BYTES);
int value = getByteAtOffset_BE(seg, roff) & 0xFF;
int value = (isBigEndian? getByteAtOffset_BE(seg, roff) : getByteAtOffset_LE(seg, roff)) & 0xFF;
roff += Byte.BYTES;
return value;
}
@ -158,39 +159,55 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public int readUnsignedByte(int roff) {
checkRead(roff, Byte.BYTES);
return getByteAtOffset_BE(seg, roff) & 0xFF;
return (isBigEndian? getByteAtOffset_BE(seg, roff) : getByteAtOffset_LE(seg, roff)) & 0xFF;
}
@Override
public Buf writeByte(byte value) {
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, value);
} else {
setByteAtOffset_LE(seg, woff, value);
}
woff += Byte.BYTES;
return this;
}
@Override
public Buf writeByte(int woff, byte value) {
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, value);
} else {
setByteAtOffset_LE(seg, woff, value);
}
return this;
}
@Override
public Buf writeUnsignedByte(int value) {
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, (byte) (value & 0xFF));
} else {
setByteAtOffset_LE(seg, woff, (byte) (value & 0xFF));
}
woff += Byte.BYTES;
return this;
}
@Override
public Buf writeUnsignedByte(int woff, int value) {
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, (byte) (value & 0xFF));
} else {
setByteAtOffset_LE(seg, woff, (byte) (value & 0xFF));
}
return this;
}
@Override
public char readChar() {
checkRead(roff, 2);
char value = getCharAtOffset_BE(seg, roff);
char value = (isBigEndian? getCharAtOffset_BE(seg, roff) : getCharAtOffset_LE(seg, roff));
roff += 2;
return value;
}
@ -198,7 +215,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public char readChar(int roff) {
checkRead(roff, 2);
return getCharAtOffset_BE(seg, roff);
return (isBigEndian? getCharAtOffset_BE(seg, roff) : getCharAtOffset_LE(seg, roff));
}
@Override
@ -215,16 +232,38 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return getCharAtOffset_LE(seg, roff);
}
@Override
public char readCharBE() {
checkRead(roff, 2);
char value = getCharAtOffset_BE(seg, roff);
roff += 2;
return value;
}
@Override
public char readCharBE(int roff) {
checkRead(roff, 2);
return getCharAtOffset_BE(seg, roff);
}
@Override
public Buf writeChar(char value) {
if (isBigEndian) {
setCharAtOffset_BE(seg, woff, value);
} else {
setCharAtOffset_LE(seg, woff, value);
}
woff += 2;
return this;
}
@Override
public Buf writeChar(int woff, char value) {
if (isBigEndian) {
setCharAtOffset_BE(seg, woff, value);
} else {
setCharAtOffset_LE(seg, woff, value);
}
return this;
}
@ -241,10 +280,23 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return this;
}
@Override
public Buf writeCharBE(char value) {
setCharAtOffset_BE(seg, woff, value);
woff += 2;
return this;
}
@Override
public Buf writeCharBE(int woff, char value) {
setCharAtOffset_BE(seg, woff, value);
return this;
}
@Override
public short readShort() {
checkRead(roff, Short.BYTES);
short value = getShortAtOffset_BE(seg, roff);
short value = (isBigEndian? getShortAtOffset_BE(seg, roff) : getShortAtOffset_LE(seg, roff));
roff += Short.BYTES;
return value;
}
@ -252,7 +304,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public short readShort(int roff) {
checkRead(roff, Short.BYTES);
return getShortAtOffset_BE(seg, roff);
return (isBigEndian? getShortAtOffset_BE(seg, roff) : getShortAtOffset_LE(seg, roff));
}
@Override
@ -269,10 +321,24 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return getShortAtOffset_LE(seg, roff);
}
@Override
public short readShortBE() {
checkRead(roff, Short.BYTES);
short value = getShortAtOffset_BE(seg, roff);
roff += Short.BYTES;
return value;
}
@Override
public short readShortBE(int roff) {
checkRead(roff, Short.BYTES);
return getShortAtOffset_BE(seg, roff);
}
@Override
public int readUnsignedShort() {
checkRead(roff, Short.BYTES);
int value = getShortAtOffset_BE(seg, roff) & 0xFFFF;
int value = (isBigEndian? getShortAtOffset_BE(seg, roff) : getShortAtOffset_LE(seg, roff)) & 0xFFFF;
roff += Short.BYTES;
return value;
}
@ -280,7 +346,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public int readUnsignedShort(int roff) {
checkRead(roff, Short.BYTES);
return getShortAtOffset_BE(seg, roff) & 0xFFFF;
return (isBigEndian? getShortAtOffset_BE(seg, roff) : getShortAtOffset_LE(seg, roff)) & 0xFFFF;
}
@Override
@ -297,16 +363,38 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return getShortAtOffset_LE(seg, roff) & 0xFFFF;
}
@Override
public int readUnsignedShortBE() {
checkRead(roff, Short.BYTES);
int value = getShortAtOffset_BE(seg, roff) & 0xFFFF;
roff += Short.BYTES;
return value;
}
@Override
public int readUnsignedShortBE(int roff) {
checkRead(roff, Short.BYTES);
return getShortAtOffset_BE(seg, roff) & 0xFFFF;
}
@Override
public Buf writeShort(short value) {
if (isBigEndian) {
setShortAtOffset_BE(seg, woff, value);
} else {
setShortAtOffset_LE(seg, woff, value);
}
woff += Short.BYTES;
return this;
}
@Override
public Buf writeShort(int woff, short value) {
if (isBigEndian) {
setShortAtOffset_BE(seg, woff, value);
} else {
setShortAtOffset_LE(seg, woff, value);
}
return this;
}
@ -323,16 +411,37 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return this;
}
@Override
public Buf writeShortBE(short value) {
setShortAtOffset_BE(seg, woff, value);
woff += Short.BYTES;
return this;
}
@Override
public Buf writeShortBE(int woff, short value) {
setShortAtOffset_BE(seg, woff, value);
return this;
}
@Override
public Buf writeUnsignedShort(int value) {
if (isBigEndian) {
setShortAtOffset_BE(seg, woff, (short) (value & 0xFFFF));
} else {
setShortAtOffset_LE(seg, woff, (short) (value & 0xFFFF));
}
woff += Short.BYTES;
return this;
}
@Override
public Buf writeUnsignedShort(int woff, int value) {
if (isBigEndian) {
setShortAtOffset_BE(seg, woff, (short) (value & 0xFFFF));
} else {
setShortAtOffset_LE(seg, woff, (short) (value & 0xFFFF));
}
return this;
}
@ -349,14 +458,27 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return this;
}
@Override
public Buf writeUnsignedShortBE(int value) {
setShortAtOffset_BE(seg, woff, (short) (value & 0xFFFF));
woff += Short.BYTES;
return this;
}
@Override
public Buf writeUnsignedShortBE(int woff, int value) {
setShortAtOffset_BE(seg, woff, (short) (value & 0xFFFF));
return this;
}
@Override
public int readMedium() {
checkRead(roff, 3);
int value = isBigEndian?
getByteAtOffset_BE(seg, roff) << 16 |
getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF :
getByteAtOffset_BE(seg, roff) & 0xFF |
getByteAtOffset_BE(seg, roff) & 0xFF |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) << 16;
roff += 3;
@ -366,9 +488,13 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public int readMedium(int roff) {
checkRead(roff, 3);
return getByteAtOffset_BE(seg, roff) << 16 |
return isBigEndian?
getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF;
getByteAtOffset_BE(seg, roff + 2) & 0xFF :
getByteAtOffset_BE(seg, roff) & 0xFF |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) << 16;
}
@Override
@ -389,12 +515,34 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
getByteAtOffset_BE(seg, roff + 2) << 16;
}
@Override
public int readMediumBE() {
checkRead(roff, 3);
int value = getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF;
roff += 3;
return value;
}
@Override
public int readMediumBE(int roff) {
checkRead(roff, 3);
return getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF;
}
@Override
public int readUnsignedMedium() {
checkRead(roff, 3);
int value = (getByteAtOffset_BE(seg, roff) << 16 |
int value = isBigEndian?
(getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF) & 0xFFFFFF;
getByteAtOffset_BE(seg, roff + 2) & 0xFF) & 0xFFFFFF :
(getByteAtOffset_BE(seg, roff) & 0xFF |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) << 16) & 0xFFFFFF;
roff += 3;
return value;
}
@ -402,9 +550,13 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public int readUnsignedMedium(int roff) {
checkRead(roff, 3);
return (getByteAtOffset_BE(seg, roff) << 16 |
return isBigEndian?
(getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF) & 0xFFFFFF;
getByteAtOffset_BE(seg, roff + 2) & 0xFF) & 0xFFFFFF :
(getByteAtOffset_BE(seg, roff) & 0xFF |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) << 16) & 0xFFFFFF;
}
@Override
@ -425,12 +577,36 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
getByteAtOffset_BE(seg, roff + 2) << 16) & 0xFFFFFF;
}
@Override
public int readUnsignedMediumBE() {
checkRead(roff, 3);
int value = (getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF) & 0xFFFFFF;
roff += 3;
return value;
}
@Override
public int readUnsignedMediumBE(int roff) {
checkRead(roff, 3);
return (getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF) & 0xFFFFFF;
}
@Override
public Buf writeMedium(int value) {
checkWrite(woff, 3);
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, (byte) (value >> 16));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
setByteAtOffset_BE(seg, woff + 2, (byte) (value & 0xFF));
} else {
setByteAtOffset_BE(seg, woff, (byte) (value & 0xFF));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
setByteAtOffset_BE(seg, woff + 2, (byte) (value >> 16 & 0xFF));
}
woff += 3;
return this;
}
@ -438,9 +614,15 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public Buf writeMedium(int woff, int value) {
checkWrite(woff, 3);
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, (byte) (value >> 16));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
setByteAtOffset_BE(seg, woff + 2, (byte) (value & 0xFF));
} else {
setByteAtOffset_BE(seg, woff, (byte) (value & 0xFF));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
setByteAtOffset_BE(seg, woff + 2, (byte) (value >> 16 & 0xFF));
}
return this;
}
@ -464,7 +646,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
}
@Override
public Buf writeUnsignedMedium(int value) {
public Buf writeMediumBE(int value) {
checkWrite(woff, 3);
setByteAtOffset_BE(seg, woff, (byte) (value >> 16));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
@ -474,7 +656,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
}
@Override
public Buf writeUnsignedMedium(int woff, int value) {
public Buf writeMediumBE(int woff, int value) {
checkWrite(woff, 3);
setByteAtOffset_BE(seg, woff, (byte) (value >> 16));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
@ -482,6 +664,37 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return this;
}
@Override
public Buf writeUnsignedMedium(int value) {
checkWrite(woff, 3);
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, (byte) (value >> 16));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
setByteAtOffset_BE(seg, woff + 2, (byte) (value & 0xFF));
} else {
setByteAtOffset_BE(seg, woff, (byte) (value & 0xFF));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
setByteAtOffset_BE(seg, woff + 2, (byte) (value >> 16 & 0xFF));
}
woff += 3;
return this;
}
@Override
public Buf writeUnsignedMedium(int woff, int value) {
checkWrite(woff, 3);
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, (byte) (value >> 16));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
setByteAtOffset_BE(seg, woff + 2, (byte) (value & 0xFF));
} else {
setByteAtOffset_BE(seg, woff, (byte) (value & 0xFF));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
setByteAtOffset_BE(seg, woff + 2, (byte) (value >> 16 & 0xFF));
}
return this;
}
@Override
public Buf writeUnsignedMediumLE(int value) {
checkWrite(woff, 3);
@ -501,10 +714,29 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return this;
}
@Override
public Buf writeUnsignedMediumBE(int value) {
checkWrite(woff, 3);
setByteAtOffset_BE(seg, woff, (byte) (value >> 16));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
setByteAtOffset_BE(seg, woff + 2, (byte) (value & 0xFF));
woff += 3;
return this;
}
@Override
public Buf writeUnsignedMediumBE(int woff, int value) {
checkWrite(woff, 3);
setByteAtOffset_BE(seg, woff, (byte) (value >> 16));
setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));
setByteAtOffset_BE(seg, woff + 2, (byte) (value & 0xFF));
return this;
}
@Override
public int readInt() {
checkRead(roff, Integer.BYTES);
int value = getIntAtOffset_BE(seg, roff);
int value = (isBigEndian? getIntAtOffset_BE(seg, roff) : getIntAtOffset_LE(seg, roff));
roff += Integer.BYTES;
return value;
}
@ -512,7 +744,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public int readInt(int roff) {
checkRead(roff, Integer.BYTES);
return getIntAtOffset_BE(seg, roff);
return (isBigEndian? getIntAtOffset_BE(seg, roff) : getIntAtOffset_LE(seg, roff));
}
@Override
@ -529,10 +761,24 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return getIntAtOffset_LE(seg, roff);
}
@Override
public int readIntBE() {
checkRead(roff, Integer.BYTES);
int value = getIntAtOffset_BE(seg, roff);
roff += Integer.BYTES;
return value;
}
@Override
public int readIntBE(int roff) {
checkRead(roff, Integer.BYTES);
return getIntAtOffset_BE(seg, roff);
}
@Override
public long readUnsignedInt() {
checkRead(roff, Integer.BYTES);
long value = getIntAtOffset_BE(seg, roff) & 0xFFFFFFFFL;
long value = (isBigEndian? getIntAtOffset_BE(seg, roff) : getIntAtOffset_LE(seg, roff)) & 0xFFFFFFFFL;
roff += Integer.BYTES;
return value;
}
@ -540,7 +786,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public long readUnsignedInt(int roff) {
checkRead(roff, Integer.BYTES);
return getIntAtOffset_BE(seg, roff) & 0xFFFFFFFFL;
return (isBigEndian? getIntAtOffset_BE(seg, roff) : getIntAtOffset_LE(seg, roff)) & 0xFFFFFFFFL;
}
@Override
@ -557,16 +803,38 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return getIntAtOffset_LE(seg, roff) & 0xFFFFFFFFL;
}
@Override
public long readUnsignedIntBE() {
checkRead(roff, Integer.BYTES);
long value = getIntAtOffset_BE(seg, roff) & 0xFFFFFFFFL;
roff += Integer.BYTES;
return value;
}
@Override
public long readUnsignedIntBE(int roff) {
checkRead(roff, Integer.BYTES);
return getIntAtOffset_BE(seg, roff) & 0xFFFFFFFFL;
}
@Override
public Buf writeInt(int value) {
if (isBigEndian) {
setIntAtOffset_BE(seg, woff, value);
} else {
setIntAtOffset_LE(seg, woff, value);
}
woff += Integer.BYTES;
return this;
}
@Override
public Buf writeInt(int woff, int value) {
if (isBigEndian) {
setIntAtOffset_BE(seg, woff, value);
} else {
setIntAtOffset_LE(seg, woff, value);
}
return this;
}
@ -583,16 +851,37 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return this;
}
@Override
public Buf writeIntBE(int value) {
setIntAtOffset_BE(seg, woff, value);
woff += Integer.BYTES;
return this;
}
@Override
public Buf writeIntBE(int woff, int value) {
setIntAtOffset_BE(seg, woff, value);
return this;
}
@Override
public Buf writeUnsignedInt(long value) {
if (isBigEndian) {
setIntAtOffset_BE(seg, woff, (int) (value & 0xFFFFFFFFL));
} else {
setIntAtOffset_LE(seg, woff, (int) (value & 0xFFFFFFFFL));
}
woff += Integer.BYTES;
return this;
}
@Override
public Buf writeUnsignedInt(int woff, long value) {
if (isBigEndian) {
setIntAtOffset_BE(seg, woff, (int) (value & 0xFFFFFFFFL));
} else {
setIntAtOffset_LE(seg, woff, (int) (value & 0xFFFFFFFFL));
}
return this;
}
@ -609,10 +898,23 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return this;
}
@Override
public Buf writeUnsignedIntBE(long value) {
setIntAtOffset_BE(seg, woff, (int) (value & 0xFFFFFFFFL));
woff += Integer.BYTES;
return this;
}
@Override
public Buf writeUnsignedIntBE(int woff, long value) {
setIntAtOffset_BE(seg, woff, (int) (value & 0xFFFFFFFFL));
return this;
}
@Override
public float readFloat() {
checkRead(roff, Float.BYTES);
float value = getFloatAtOffset_BE(seg, roff);
float value = (isBigEndian? getFloatAtOffset_BE(seg, roff) : getFloatAtOffset_LE(seg, roff));
roff += Float.BYTES;
return value;
}
@ -620,7 +922,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public float readFloat(int roff) {
checkRead(roff, Float.BYTES);
return getFloatAtOffset_BE(seg, roff);
return (isBigEndian? getFloatAtOffset_BE(seg, roff) : getFloatAtOffset_LE(seg, roff));
}
@Override
@ -637,16 +939,38 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return getFloatAtOffset_LE(seg, roff);
}
@Override
public float readFloatBE() {
checkRead(roff, Float.BYTES);
float value = getFloatAtOffset_BE(seg, roff);
roff += Float.BYTES;
return value;
}
@Override
public float readFloatBE(int roff) {
checkRead(roff, Float.BYTES);
return getFloatAtOffset_BE(seg, roff);
}
@Override
public Buf writeFloat(float value) {
if (isBigEndian) {
setFloatAtOffset_BE(seg, woff, value);
} else {
setFloatAtOffset_LE(seg, woff, value);
}
woff += Float.BYTES;
return this;
}
@Override
public Buf writeFloat(int woff, float value) {
if (isBigEndian) {
setFloatAtOffset_BE(seg, woff, value);
} else {
setFloatAtOffset_LE(seg, woff, value);
}
return this;
}
@ -663,10 +987,23 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return this;
}
@Override
public Buf writeFloatBE(float value) {
setFloatAtOffset_BE(seg, woff, value);
woff += Float.BYTES;
return this;
}
@Override
public Buf writeFloatBE(int woff, float value) {
setFloatAtOffset_BE(seg, woff, value);
return this;
}
@Override
public long readLong() {
checkRead(roff, Long.BYTES);
long value = getLongAtOffset_BE(seg, roff);
long value = (isBigEndian? getLongAtOffset_BE(seg, roff) : getLongAtOffset_LE(seg, roff));
roff += Long.BYTES;
return value;
}
@ -674,7 +1011,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public long readLong(int roff) {
checkRead(roff, Long.BYTES);
return getLongAtOffset_BE(seg, roff);
return (isBigEndian? getLongAtOffset_BE(seg, roff) : getLongAtOffset_LE(seg, roff));
}
@Override
@ -691,16 +1028,38 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return getLongAtOffset_LE(seg, roff);
}
@Override
public long readLongBE() {
checkRead(roff, Long.BYTES);
long value = getLongAtOffset_BE(seg, roff);
roff += Long.BYTES;
return value;
}
@Override
public long readLongBE(int roff) {
checkRead(roff, Long.BYTES);
return getLongAtOffset_BE(seg, roff);
}
@Override
public Buf writeLong(long value) {
if (isBigEndian) {
setLongAtOffset_BE(seg, woff, value);
} else {
setLongAtOffset_LE(seg, woff, value);
}
woff += Long.BYTES;
return this;
}
@Override
public Buf writeLong(int woff, long value) {
if (isBigEndian) {
setLongAtOffset_BE(seg, woff, value);
} else {
setLongAtOffset_LE(seg, woff, value);
}
return this;
}
@ -717,10 +1076,23 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return this;
}
@Override
public Buf writeLongBE(long value) {
setLongAtOffset_BE(seg, woff, value);
woff += Long.BYTES;
return this;
}
@Override
public Buf writeLongBE(int woff, long value) {
setLongAtOffset_BE(seg, woff, value);
return this;
}
@Override
public double readDouble() {
checkRead(roff, Double.BYTES);
double value = getDoubleAtOffset_BE(seg, roff);
double value = (isBigEndian? getDoubleAtOffset_BE(seg, roff) : getDoubleAtOffset_LE(seg, roff));
roff += Double.BYTES;
return value;
}
@ -728,7 +1100,7 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
@Override
public double readDouble(int roff) {
checkRead(roff, Double.BYTES);
return getDoubleAtOffset_BE(seg, roff);
return (isBigEndian? getDoubleAtOffset_BE(seg, roff) : getDoubleAtOffset_LE(seg, roff));
}
@Override
@ -745,16 +1117,38 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
return getDoubleAtOffset_LE(seg, roff);
}
@Override
public double readDoubleBE() {
checkRead(roff, Double.BYTES);
double value = getDoubleAtOffset_BE(seg, roff);
roff += Double.BYTES;
return value;
}
@Override
public double readDoubleBE(int roff) {
checkRead(roff, Double.BYTES);
return getDoubleAtOffset_BE(seg, roff);
}
@Override
public Buf writeDouble(double value) {
if (isBigEndian) {
setDoubleAtOffset_BE(seg, woff, value);
} else {
setDoubleAtOffset_LE(seg, woff, value);
}
woff += Double.BYTES;
return this;
}
@Override
public Buf writeDouble(int woff, double value) {
if (isBigEndian) {
setDoubleAtOffset_BE(seg, woff, value);
} else {
setDoubleAtOffset_LE(seg, woff, value);
}
return this;
}
@ -770,6 +1164,19 @@ class BBuf extends RcSupport<Buf, BBuf> implements Buf {
setDoubleAtOffset_LE(seg, woff, value);
return this;
}
@Override
public Buf writeDoubleBE(double value) {
setDoubleAtOffset_BE(seg, woff, value);
woff += Double.BYTES;
return this;
}
@Override
public Buf writeDoubleBE(int woff, double value) {
setDoubleAtOffset_BE(seg, woff, value);
return this;
}
// </editor-fold>
// ### CODEGEN END primitive accessors implementation

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -22,24 +22,49 @@ public final class Codegen {
"primitive accessors implementation", Codegen::primitiveAccessorsImplementation,
"primitive accessors tests", Codegen::primitiveAccessorsTests);
enum Order {
DF /*default as configured for buffer*/, BE, LE;
public String suffix() {
return this == DF? "" : name();
}
public String title() {
switch (this) {
case BE: return "Big";
case LE: return "Little";
}
return "Default";
}
public String endianDesc() {
switch (this) {
case BE: return "big-endian";
case LE: return "little-endian";
}
return "the {@link #order() configured} default";
}
}
enum Type {
BYTE("byte", "Byte", "Byte.BYTES", Byte.BYTES, false, "two's complement 8-bit", "int"),
CHAR("char", "Char", "2", 2, true, "2-byte UTF-16", null),
SHORT("short", "Short", "Short.BYTES", Short.BYTES, true, "two's complement 16-bit", "int"),
MED("int", "Medium", "3", 3, true, "two's complement 24-bit", "int") {
@Override
public String load(boolean le, boolean unsigned) {
String indent = " ";
public String load(Order ord, boolean unsigned) {
String indent = " ".repeat(ord == Order.DF? 16 : 20);
String tailPart = unsigned? ") & 0x" + "FF".repeat(actualSize) : "";
if (le) {
return (unsigned? "(" : "") +
"getByteAtOffset_BE(seg, roff) & 0xFF |\n" +
indent +
"(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |\n" +
indent +
"getByteAtOffset_BE(seg, roff + 2) << 16" +
tailPart;
} else {
switch (ord) {
case BE: return loadBE(unsigned, indent, tailPart);
case LE: return loadLE(unsigned, indent, tailPart);
}
return "isBigEndian?\n" +
loadBE(unsigned, indent, tailPart) + " : \n" +
loadLE(unsigned, indent, tailPart);
}
private String loadBE(boolean unsigned, String indent, String tailPart) {
return (unsigned? "(" : "") +
"getByteAtOffset_BE(seg, roff) << 16 |\n" +
indent +
@ -48,24 +73,52 @@ public final class Codegen {
"getByteAtOffset_BE(seg, roff + 2) & 0xFF" +
tailPart;
}
private String loadLE(boolean unsigned, String indent, String tailPart) {
return (unsigned? "(" : "") +
"getByteAtOffset_BE(seg, roff) & 0xFF |\n" +
indent +
"(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |\n" +
indent +
"getByteAtOffset_BE(seg, roff + 2) << 16" +
tailPart;
}
@Override
public String store(boolean le, boolean unsigned) {
String indent = " ";
if (le) {
return "setByteAtOffset_BE(seg, woff, (byte) (value & 0xFF));\n" +
public String store(Order ord, boolean unsigned) {
String indent = " ".repeat(ord == Order.DF? 12 : 8);
switch (ord) {
case BE: return storeBE(indent);
case LE: return storeLE(indent);
}
String indentOuter = " ".repeat(8);
return "if (isBigEndian) {\n" +
indent +
"setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));\n" +
storeBE(indent) +
'\n' +
indentOuter +
"} else {\n" +
indent +
"setByteAtOffset_BE(seg, woff + 2, (byte) (value >> 16 & 0xFF))";
} else {
storeLE(indent) +
'\n' +
indentOuter +
'}';
}
private String storeBE(String indent) {
return "setByteAtOffset_BE(seg, woff, (byte) (value >> 16));\n" +
indent +
"setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));\n" +
indent +
"setByteAtOffset_BE(seg, woff + 2, (byte) (value & 0xFF))";
"setByteAtOffset_BE(seg, woff + 2, (byte) (value & 0xFF));";
}
private String storeLE(String indent) {
return "setByteAtOffset_BE(seg, woff, (byte) (value & 0xFF));\n" +
indent +
"setByteAtOffset_BE(seg, woff + 1, (byte) (value >> 8 & 0xFF));\n" +
indent +
"setByteAtOffset_BE(seg, woff + 2, (byte) (value >> 16 & 0xFF));";
}
},
INT("int", "Int", "Integer.BYTES", Integer.BYTES, true, "two's complement 32-bit", "long"),
@ -78,68 +131,90 @@ public final class Codegen {
protected final String title;
protected final String size;
protected final int actualSize;
protected final boolean includeLE;
protected final boolean includeLEBE;
protected final String extra;
protected final String unsignedCarrier;
Type(String type, String title, String size, int actualSize, boolean includeLE, String extra, String unsignedCarrier) {
Type(String type, String title, String size, int actualSize, boolean includeLEBE, String extra, String unsignedCarrier) {
this.type = type;
this.title = title;
this.size = size;
this.actualSize = actualSize;
this.includeLE = includeLE;
this.includeLEBE = includeLEBE;
this.extra = extra;
this.unsignedCarrier = unsignedCarrier;
}
public String title(boolean le, boolean unsigned) {
return (unsigned? "Unsigned" + title : title) + (le? "LE" : "");
public String title(Order ord, boolean unsigned) {
return (unsigned? "Unsigned" + title : title) + ord.suffix();
}
public String extraRead(boolean le, boolean unsigned) {
return getExtra("read", le, unsigned);
public String extraRead(Order ord, boolean unsigned) {
return getExtra("read", ord, unsigned);
}
public String extraWrite(boolean le, boolean unsigned) {
return getExtra("written", le, unsigned);
public String extraWrite(Order ord, boolean unsigned) {
return getExtra("written", ord, unsigned);
}
private String getExtra(String op, boolean le, boolean unsigned) {
private String getExtra(String op, Order ord, boolean unsigned) {
return "The value is " + op + " using " +
(unsigned? "an unsigned " : "a ") +
extra +
" encoding, with " +
(le? "little" : "big") +
"-endian byte order.";
" encoding,\n" +
" * with " +
ord.endianDesc() +
" byte order.";
}
public String type(boolean unsigned) {
return unsigned? unsignedCarrier : type;
}
public String load(boolean le, boolean unsigned) {
public String load(Order ord, boolean unsigned) {
boolean longCarrier = "long".equals(unsignedCarrier);
boolean intCarrier = "int".equals(unsignedCarrier);
return (unsigned && !longCarrier && !intCarrier? '(' + unsignedCarrier + ") (" : "") +
"get" +
title +
"AtOffset_" +
(le? "LE" : "BE") +
"(seg, roff)" +
getCall(ord) +
(unsigned? " & 0x" + "FF".repeat(actualSize) +
(longCarrier? 'L' : intCarrier? "" : ')') : "");
}
public String store(boolean le, boolean unsigned) {
private String getCall(Order ord) {
if (ord == Order.DF) {
return "(isBigEndian? " + getCall(Order.BE) + " : " + getCall(Order.LE) + ')';
}
return "get" +
title +
"AtOffset_" +
ord.suffix() +
"(seg, roff)";
}
public String store(Order ord, boolean unsigned) {
if (ord == Order.DF) {
String indent = " ";
return "if (isBigEndian) {\n" +
indent + " " +
store(Order.BE, unsigned) +
'\n' +
indent +
"} else {\n" +
indent + " " +
store(Order.LE, unsigned) +
'\n' +
indent +
'}';
}
boolean longCarrier = "long".equals(unsignedCarrier);
return "set" +
title +
"AtOffset_" +
(le? "LE" : "BE") +
ord.suffix() +
"(seg, woff, " +
(unsigned? '(' + type + ") (value & 0x" + "FF".repeat(actualSize) +
(longCarrier? "L)" : ")") : "value") +
')';
");";
}
public String realType(boolean unsigned) {
@ -150,7 +225,7 @@ public final class Codegen {
enum Template {
INTERFACE {
@Override
public String relativeRead(Type type, boolean le, boolean unsigned, boolean read) {
public String relativeRead(Type type, Order ord, boolean unsigned, boolean read) {
var tmpl = '\n' +
" /**\n" +
" * Get the %8$s value at the current {@link Buf#readerIndex()},\n" +
@ -161,11 +236,11 @@ public final class Codegen {
" * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than %3$s.\n" +
" */\n" +
" %1$s read%2$s();";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
@Override
public String offsetRead(Type type, boolean le, boolean unsigned, boolean read) {
public String offsetRead(Type type, Order ord, boolean unsigned, boolean read) {
var tmpl = '\n' +
" /**\n" +
" * Get the %8$s value at the given reader offset.\n" +
@ -178,11 +253,11 @@ public final class Codegen {
" * greater than or equal to {@link Buf#capacity()} minus %3$s.\n" +
" */\n" +
" %1$s read%2$s(int roff);";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
@Override
public String relativeWrite(Type type, boolean le, boolean unsigned, boolean read) {
public String relativeWrite(Type type, Order ord, boolean unsigned, boolean read) {
var tmpl = '\n' +
" /**\n" +
" * Set the given %8$s value at the current {@link Buf#writerIndex()},\n" +
@ -194,11 +269,11 @@ public final class Codegen {
" * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than %3$s.\n" +
" */\n" +
" Buf write%2$s(%1$s value);";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
@Override
public String offsetWrite(Type type, boolean le, boolean unsigned, boolean read) {
public String offsetWrite(Type type, Order ord, boolean unsigned, boolean read) {
var tmpl = '\n' +
" /**\n" +
" * Set the given %8$s value at the given write offset. The {@link Buf#writerIndex()} is not modified.\n" +
@ -211,12 +286,12 @@ public final class Codegen {
" * greater than or equal to {@link Buf#capacity()} minus %3$s.\n" +
" */\n" +
" Buf write%2$s(int woff, %1$s value);";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
},
IMPLEMENTATION {
@Override
public String relativeRead(Type type, boolean le, boolean unsigned, boolean read) {
public String relativeRead(Type type, Order ord, boolean unsigned, boolean read) {
var tmpl = '\n' +
" @Override\n" +
" public %1$s read%2$s() {\n" +
@ -225,43 +300,43 @@ public final class Codegen {
" roff += %5$s;\n" +
" return value;\n" +
" }";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
@Override
public String offsetRead(Type type, boolean le, boolean unsigned, boolean read) {
public String offsetRead(Type type, Order ord, boolean unsigned, boolean read) {
var tmpl = '\n' +
" @Override\n" +
" public %1$s read%2$s(int roff) {\n" +
" checkRead(roff, %5$s);\n" +
" return %6$s;\n" +
" }";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
@Override
public String relativeWrite(Type type, boolean le, boolean unsigned, boolean read) {
public String relativeWrite(Type type, Order ord, boolean unsigned, boolean read) {
var tmpl = '\n' +
" @Override\n" +
" public Buf write%2$s(%1$s value) {\n" +
(type == Type.MED? " checkWrite(woff, %5$s);\n" : "") +
" %7$s;\n" +
" %7$s\n" +
" woff += %5$s;\n" +
" return this;\n" +
" }";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
@Override
public String offsetWrite(Type type, boolean le, boolean unsigned, boolean read) {
public String offsetWrite(Type type, Order ord, boolean unsigned, boolean read) {
var tmpl = '\n' +
" @Override\n" +
" public Buf write%2$s(int woff, %1$s value) {\n" +
(type == Type.MED? " checkWrite(woff, %5$s);\n" : "") +
" %7$s;\n" +
" %7$s\n" +
" return this;\n" +
" }";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
},
TESTS {
@ -270,7 +345,7 @@ public final class Codegen {
int bytesAvailAfter;
@Override
public String relativeRead(Type type, boolean le, boolean unsigned, boolean read) {
public String relativeRead(Type type, Order ord, boolean unsigned, boolean read) {
prepare(type);
var tmpl = '\n' +
" @Test\n" +
@ -286,12 +361,13 @@ public final class Codegen {
" }\n" +
'\n' +
" @Test\n" +
" public void relativeReadOf%2$sMustReadWith" + (le? "Little" : "Big") + "EndianByteOrder() {\n" +
" public void relativeReadOf%2$sMustReadWith" + ord.title() + "EndianByteOrder() {\n" +
(ord == Order.DF? " buf.order(ByteOrder.BIG_ENDIAN);\n" : "") +
" assertEquals(0, buf.readableBytes());\n" +
" assertEquals(Long.BYTES, buf.writableBytes());\n" +
" %1$s value = " + testValue + ";\n" +
" buf.write%2$s(value);\n" +
" buf.writeByte(" + (le? type.actualSize - 1 : 0) + ", (byte) 0x10);\n" +
" buf.writeByte(" + (ord == Order.LE? type.actualSize - 1 : 0) + ", (byte) 0x10);\n" +
" assertEquals(" + type.actualSize + ", buf.readableBytes());\n" +
" assertEquals(" + bytesAvailAfter + ", buf.writableBytes());\n" +
" assertEquals(" + testValueByteOrder + ", buf.read%2$s());\n" +
@ -315,11 +391,11 @@ public final class Codegen {
" }\n" +
" assertEquals(" + (type.actualSize - 1) + ", buf.readableBytes());\n" +
" }";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
@Override
public String offsetRead(Type type, boolean le, boolean unsigned, boolean read) {
public String offsetRead(Type type, Order ord, boolean unsigned, boolean read) {
prepare(type);
var tmpl = '\n' +
" @Test\n" +
@ -340,10 +416,11 @@ public final class Codegen {
" }\n" +
'\n' +
" @Test\n" +
" public void offsettedReadOf%2$sMustReadWith" + (le? "Little" : "Big") + "EndianByteOrder() {\n" +
" public void offsettedReadOf%2$sMustReadWith" + ord.title() + "EndianByteOrder() {\n" +
(ord == Order.DF? " buf.order(ByteOrder.BIG_ENDIAN);\n" : "") +
" %1$s value = " + testValue + ";\n" +
" buf.write%2$s(value);\n" +
" buf.writeByte(" + (le? type.actualSize - 1 : 0) + ", (byte) 0x10);\n" +
" buf.writeByte(" + (ord == Order.LE? type.actualSize - 1 : 0) + ", (byte) 0x10);\n" +
" assertEquals(" + testValueByteOrder + ", buf.read%2$s(0));\n" +
" }\n" +
'\n' +
@ -368,13 +445,14 @@ public final class Codegen {
" // Good.\n" +
" }\n" +
" }";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
@Override
public String relativeWrite(Type type, boolean le, boolean unsigned, boolean read) {
public String relativeWrite(Type type, Order ord, boolean unsigned, boolean read) {
prepare(type);
int size = type.actualSize;
boolean le = ord == Order.LE;
int r = le? size : 1;
var tmpl = '\n' +
" @Test\n" +
@ -394,7 +472,8 @@ public final class Codegen {
" }\n" +
'\n' +
" @Test\n" +
" public void relativeWriteOf%2$sMustHave" + (le? "Little" : "Big") + "EndianByteOrder() {\n" +
" public void relativeWriteOf%2$sMustHave" + ord.title() + "EndianByteOrder() {\n" +
(ord == Order.DF? " buf.order(ByteOrder.BIG_ENDIAN);\n" : "") +
" %1$s value = " + testValue + ";\n" +
" buf.write%2$s(value);\n" +
" buf.writerIndex(Long.BYTES);\n" +
@ -407,13 +486,14 @@ public final class Codegen {
" assertEquals((byte) 0x0" + (size < 7? 0 : le? r-- : r++) + ", buf.readByte());\n" +
" assertEquals((byte) 0x0" + (size < 8? 0 : r) + ", buf.readByte());\n" +
" }";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
@Override
public String offsetWrite(Type type, boolean le, boolean unsigned, boolean read) {
public String offsetWrite(Type type, Order ord, boolean unsigned, boolean read) {
prepare(type);
int size = type.actualSize;
boolean le = ord == Order.LE;
int r = le? size : 1;
var tmpl = '\n' +
" @Test\n" +
@ -447,7 +527,8 @@ public final class Codegen {
" }\n" +
'\n' +
" @Test\n" +
" public void offsettedWriteOf%2$sMustHave" + (le? "Little" : "Big") + "EndianByteOrder() {\n" +
" public void offsettedWriteOf%2$sMustHave" + ord.title() + "EndianByteOrder() {\n" +
(ord == Order.DF? " buf.order(ByteOrder.BIG_ENDIAN);\n" : "") +
" %1$s value = " + testValue + ";\n" +
" buf.write%2$s(0, value);\n" +
" buf.writerIndex(Long.BYTES);\n" +
@ -460,7 +541,7 @@ public final class Codegen {
" assertEquals((byte) 0x0" + (size < 7? 0 : le? r-- : r++) + ", buf.readByte());\n" +
" assertEquals((byte) 0x0" + (size < 8? 0 : r) + ", buf.readByte());\n" +
" }";
return format(tmpl, type, le, unsigned, read);
return format(tmpl, type, ord, unsigned, read);
}
private void prepare(Type type) {
@ -481,10 +562,10 @@ public final class Codegen {
}
};
public abstract String relativeRead(Type type, boolean le, boolean unsigned, boolean read);
public abstract String offsetRead(Type type, boolean le, boolean unsigned, boolean read);
public abstract String relativeWrite(Type type, boolean le, boolean unsigned, boolean read);
public abstract String offsetWrite(Type type, boolean le, boolean unsigned, boolean read);
public abstract String relativeRead(Type type, Order ord, boolean unsigned, boolean read);
public abstract String offsetRead(Type type, Order ord, boolean unsigned, boolean read);
public abstract String relativeWrite(Type type, Order ord, boolean unsigned, boolean read);
public abstract String offsetWrite(Type type, Order ord, boolean unsigned, boolean read);
}
public static void main(String[] args) throws Exception {
@ -552,47 +633,55 @@ public final class Codegen {
private static Stream<String> generateAccessors(Template template, Type type) {
Builder<String> builder = Stream.builder();
builder.add(template.relativeRead(type, false, false, true));
builder.add(template.offsetRead(type, false, false, true));
if (type.includeLE) {
builder.add(template.relativeRead(type, true, false, true));
builder.add(template.offsetRead(type, true, false, true));
builder.add(template.relativeRead(type, Order.DF, false, true));
builder.add(template.offsetRead(type, Order.DF, false, true));
if (type.includeLEBE) {
builder.add(template.relativeRead(type, Order.LE, false, true));
builder.add(template.offsetRead(type, Order.LE, false, true));
builder.add(template.relativeRead(type, Order.BE, false, true));
builder.add(template.offsetRead(type, Order.BE, false, true));
}
if (type.unsignedCarrier != null) {
builder.add(template.relativeRead(type, false, true, true));
builder.add(template.offsetRead(type, false, true, true));
if (type.includeLE) {
builder.add(template.relativeRead(type, true, true, true));
builder.add(template.offsetRead(type, true, true, true));
builder.add(template.relativeRead(type, Order.DF, true, true));
builder.add(template.offsetRead(type, Order.DF, true, true));
if (type.includeLEBE) {
builder.add(template.relativeRead(type, Order.LE, true, true));
builder.add(template.offsetRead(type, Order.LE, true, true));
builder.add(template.relativeRead(type, Order.BE, true, true));
builder.add(template.offsetRead(type, Order.BE, true, true));
}
}
builder.add(template.relativeWrite(type, false, false, false));
builder.add(template.offsetWrite(type, false, false, false));
if (type.includeLE) {
builder.add(template.relativeWrite(type, true, false, false));
builder.add(template.offsetWrite(type, true, false, false));
builder.add(template.relativeWrite(type, Order.DF, false, false));
builder.add(template.offsetWrite(type, Order.DF, false, false));
if (type.includeLEBE) {
builder.add(template.relativeWrite(type, Order.LE, false, false));
builder.add(template.offsetWrite(type, Order.LE, false, false));
builder.add(template.relativeWrite(type, Order.BE, false, false));
builder.add(template.offsetWrite(type, Order.BE, false, false));
}
if (type.unsignedCarrier != null) {
builder.add(template.relativeWrite(type, false, true, false));
builder.add(template.offsetWrite(type, false, true, false));
if (type.includeLE) {
builder.add(template.relativeWrite(type, true, true, false));
builder.add(template.offsetWrite(type, true, true, false));
builder.add(template.relativeWrite(type, Order.DF, true, false));
builder.add(template.offsetWrite(type, Order.DF, true, false));
if (type.includeLEBE) {
builder.add(template.relativeWrite(type, Order.LE, true, false));
builder.add(template.offsetWrite(type, Order.LE, true, false));
builder.add(template.relativeWrite(type, Order.BE, true, false));
builder.add(template.offsetWrite(type, Order.BE, true, false));
}
}
return builder.build();
}
private static String format(String format, Type type, boolean le, boolean unsigned, boolean read) {
private static String format(String format, Type type, Order ord, boolean unsigned, boolean read) {
var carrier = type.type(unsigned);
var title = type.title(le, unsigned);
var title = type.title(ord, unsigned);
var size = ALL_DIGITS.matcher(type.size).matches()? type.size : "{@link " + type.size.replace('.', '#') + '}';
var extra = read? type.extraRead(le, unsigned) : type.extraWrite(le, unsigned);
var extra = read? type.extraRead(ord, unsigned) : type.extraWrite(ord, unsigned);
var realSize = type.size;
return String.format(format, carrier, title, size, extra, realSize,
type.load(le, unsigned), type.store(le, unsigned),
type.load(ord, unsigned), type.store(ord, unsigned),
type.realType(unsigned));
}
}