Parsing byte array containg fields of unknown length

后端 未结 5 1329
鱼传尺愫
鱼传尺愫 2021-01-12 15:26

I am parsing in Java a byte array having the following specification:

Trace data format:
    - 4 bytes containing the Id.
    - 4 bytes containing the addres         


        
5条回答
  •  -上瘾入骨i
    2021-01-12 16:05

    Just to add another possibility for Michael's answer.

    Assuming that N is the same for both fields, and since the same letter is used I would guess that this is the case, the field positions would be like this:

    int len = array.length;
    int varLen = len - 5*4;
    int fieldPos[] = new int[7];
    fieldPos[0] = 0;
    fieldPos[1] = 4;
    fieldPos[2] = 8;
    fieldPos[3] = 8 + varLen;
    fieldPos[4] = 8 + 2*varLen;
    fieldPos[5] = 8 + 2*varLen + 4;
    fieldPos[6] = 8 + 2*varLen + 8;
    

提交回复
热议问题