I am trying to parse an OSI file, however when I use the OSITrace.py for getting the messages it cannot parse the file.
The code where the problem happens is located at OSITrace.py function retrieve_message().
while i < len(serialized_message): message = MESSAGES_TYPE[self.type_name]() message_length = struct.unpack("<L", serialized_message[i:INT_LENGTH+i])[0] message.ParseFromString(bytearray(serialized_message)) message.ParseFromString(serialized_message[i+INT_LENGTH:i+INT_LENGTH+message_length]) i += message_length + INT_LENGTH self.message_offsets.append(i)
The problem is at the struct.unpack(struct.unpack("<L", serialized_message[i:INT_LENGTH+i])[0]) as it returns a huge integer number, which then skips most of the message on the next iteration.
When I get rid of the struct.unpack(), to parse the whole message, the program runs but it also returns -->
RuntimeWarning: Unexpected end-group tag: Not all data was converted
message.ParseFromString(serialized_message)#[i+INT_LENGTH:i+INT_LENGTH+message_length])
I am trying to parse an OSI file, however when I use the OSITrace.py for getting the messages it cannot parse the file. The code where the problem happens is located at OSITrace.py function retrieve_message().
while i < len(serialized_message): message = MESSAGES_TYPE[self.type_name]() message_length = struct.unpack("<L", serialized_message[i:INT_LENGTH+i])[0] message.ParseFromString(bytearray(serialized_message)) message.ParseFromString(serialized_message[i+INT_LENGTH:i+INT_LENGTH+message_length]) i += message_length + INT_LENGTH self.message_offsets.append(i)
The problem is at the struct.unpack(struct.unpack("<L", serialized_message[i:INT_LENGTH+i])[0]) as it returns a huge integer number, which then skips most of the message on the next iteration.I have tried changing the format (from litle-endian to big-endian) as is shown in this Stack-Overflow thread : https://stackoverflow.com/questions/65999969/struct-unpack-returning-very-large-value-python
When I get rid of the struct.unpack(), to parse the whole message, the program runs but it also returns --> RuntimeWarning: Unexpected end-group tag: Not all data was converted message.ParseFromString(serialized_message)#[i+INT_LENGTH:i+INT_LENGTH+message_length])
How could I fix this problem?
Thank You.