Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Especially for Java the templates have been becoming more and more complex. Especially when we would be adding all of the "byte order setting" this would become quite unmaintainable.

The idea was to create a set of static functions, that can be imported with static imports, that handle the logic for the different types of fields have.

Every field method would have the individual read/write operation as first argument, followed by all the mandatory pieces of information.

Optional attributes would be passed with var-arg parameters at the end. 

Code Block
// Simple Types
int apple = simpleFieldWrapper(() -> readBuffer.readUnsignedByte("IntegerEncoding", 4), WithByteOrder(ByteOrder.LITTLE_ENDIAN))
;
// Complex Type
Banana banana = simpleFieldWrapper(() -> readBuffer.readUnsignedByte("IntegerEncoding", 4), WithByteOrder(ByteOrder.LITTLE_ENDIAN), WithContext("banana"));
// Optional Fields
Banana banana = optionalFieldWrapper(() -> readBuffer.readUnsignedByte("IntegerEncoding", 4), (apple > 10) , WithByteOrder(ByteOrder.LITTLE_ENDIAN), WithContext("banana"));
// Const Fields
int coolConst = constFieldWrapper(() -> readBuffer.readUnsignedByte("IntegerEncoding", 4), 0x04, WithByteOrder(ByteOrder.LITTLE_ENDIAN));
...