I'm creating a binary parser using Python.
However, it is giving an EOF error
even while the bytes on the data file is still left.
Did anyone face the same issue? And anyway to overcome this?
from btsv3 import Btsv3
import os
import binascii
import csv
for root, dirs, files in os.walk("./Perf/BTS/", topdown=False):
for name in files:
g = Btsv3.from_file(os.path.join(root, name))
if g.header.version == 3:
print(os.path.join(root, name), "Version 3")
# Header
print("BTS ID:", g.header.btsid, " | VERSION:", g.header.version, " | TOTAL LENGTH:", g.header.len, "\n")
# Payload
print("L3 perf data of BTS")
print("Payload tag:", g.payload.l3tag)
print("Payload length:", g.payload.l3len)
Typically, an unexpected EOFError is a sign that something is wrong with format specification, and parsing has gone awry.
Code generated by ksc is actually fairly readable, so you can debug it as well. You can examine the stack trace provided with EOFError, and see where exactly it happens. If needed, you can add more debug print right into ksc-generated parser code, or run it under a debugger, etc.
Another option is to load your .ksy into some sort of visualizer (i.e. this command-line one or this WebIDE) and see if that would become clearer where the problem is.