Java – parse byte array containing unknown length field
I parse a byte array with the following specifications in Java:
Trace data format: - 4 bytes containing the Id. - 4 bytes containing the address. - N bytes containing the first name,where 0 < N < 32 - N bytes containing the last name,where 0 < N < 32 - 4 bytes containing the Minimum - 4 bytes containing the Maximum - 4 bytes containing the Resource Default Level
Today I don't see any solution for parsing this array to get 7 variables of the correct type Are you sure or I missed the magic function in Java that allows you to find the string "limit" in the byte array (I can't see how the minimum value is distinguished from its associated ASCII characters)
Is there any "Convention" for special characters between two strings?
Solution
Well, you know, the first name starts with byte 9 and the last name ends with byte (lenght - 13) What is uncertain is how to find the end of the first name and the beginning of the last name I see some possible messages:
>If the format is defined by the C programmer, the two name fields are likely to terminate with empty bytes, because this is the C convention of the string. > If it is defined by a java programmer, it can be written by writeutf (), which means that the specification of byte count is likely to be wrong However, this at least specifies the encoding, otherwise it is an open issue. > If it is defined by a COBOL programmer, these two fields can be fixed length and filled with zeros or spaces, and the format specification lists the payload length instead of the field length. > If it is defined by a really incompetent programmer (no matter what language), it contains two names without separators or counts, so it is impossible to actually separate them (if you don't have this information, there is no "magic" function, Java or other things that can be fabricated out of thin air) I think you might want your last name to always start with a capital letter. No one uses double names or all capital letters