If, for example, I am given requirements of message structure similar to the one down below:
Are there any libraries in Java to make it done quicker?
Or I have to create it manually as a separate class with byte arrays and setters/getters?
You can probably benefit from the utility methods in the ByteBuffer class instead of handling a byte array directly. You'll find methods for getting and setting multi-byte integers (e.g. getShort, putInt, putLong) and you can also control the byte order (big or little endian).
You can then wrap the ByteBuffer in another class with meaningful method names, e.g:
int getType() {
return bb.getInt(2); // offset 2
}
void setType(int type) {
bb.putInt(2, type);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With