I need to parse and encode to a legacy binary message format in Java. I began by using DataOutputStream to read/write primitive types but the problem I\'m having is that the mes
Just to add to pholser's answer, I think the Preon version would be something like this:
class DataStructure {
@BoundNumber(size="32") long first; // uint32
@Bound boolean second; // boolean
@Bound boolean third; // boolean
@BoundNumber(size="32") long fourth; // uint32
@BoundNumber(size="4") int fifth; // enum
@BoundString(size="32") String sixth; // string
}
... but in reality, you can make your life even easier by using Preon's support for dealing with enumerations directly.
Creating a Codec
for it and using it to decode some data would be something like this:
Codec codec = Codecs.create(DataStructure.class)
DataStructure data = Codecs.decode(codec, ....)