How to parse/encode binary message formats?

前端 未结 5 1545
天涯浪人
天涯浪人 2021-02-09 05:59

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

5条回答
  •  -上瘾入骨i
    2021-02-09 06:10

    with Java Binary Block Parser the script to parse the message will be

      class Parsed {
        @Bin int field1;
        @Bin (type = BinType.BIT) boolean field2;
        @Bin(type = BinType.BIT) boolean field3;
        @Bin int field4;
        @Bin(type = BinType.BIT) int enums;
        @Bin(type = BinType.UBYTE_ARRAY) String str;
      }
    
      Parsed parsed = JBBPParser.prepare("int field1; bit field2; bit field3; int field4; bit:4 enums; ubyte [32] str;").parse(STREAM).mapTo(Parsed.class);
    

提交回复
热议问题