Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function "_decode_event_table" (util.py) has issue w/ returned data types? #31

Open
SaxonWood opened this issue Mar 9, 2024 · 0 comments

Comments

@SaxonWood
Copy link

I think the function "_decode_event_table" (util.py) has an issue with the return data types of element2 ... 4 nested in the returned EventEntry object. As per EventEntry class definition, the element2 ... 4 should be bytes. But the function _decode_event_table returns element2 ... 4 as Integers.
The code sniplet below shows already my suggestion to fix this. Note that "cli.py" would need an update as well to handle bytes rather than integers.


def _decode_event_table(data: bytes) -> Tuple[datetime, Dict[datetime, EventEntry]]:
    '''
    Helper function to decode the event table type.
    '''
    timestamp = datetime.fromtimestamp(struct.unpack('>I', data[0:4])[0])
    tabval: Dict[datetime, EventEntry] = dict()
    assert len(data) % 4 == 0
    assert (len(data) - 4) % 20 == 0
    for pair in range(0, int(len(data) / 4 - 1), 5):
        # this is most likely a single byte of information, but this is not sure yet
        # entry_type = bytes([struct.unpack('>I', data[4 + pair * 4:4 + pair * 4 + 4])[0]]).decode('ascii')
        entry_type = struct.unpack('>I', data[4 + pair * 4:4 + pair * 4 + 4])[0]
        timestamp = datetime.fromtimestamp(struct.unpack('>I', data[4 + pair * 4 + 4:4 + pair * 4 + 8])[0])
#       element2 = struct.unpack('>I', data[4 + pair * 4 + 8:4 + pair * 4 + 12])[0]
#       element3 = struct.unpack('>I', data[4 + pair * 4 + 12:4 + pair * 4 + 16])[0]
#       element4 = struct.unpack('>I', data[4 + pair * 4 + 16:4 + pair * 4 + 20])[0]
        element2 = data[4 + pair * 4 +  8:4 + pair * 4 + 12]   ### saxonwood
        element3 = data[4 + pair * 4 + 12:4 + pair * 4 + 16]   ### saxonwood
        element4 = data[4 + pair * 4 + 16:4 + pair * 4 + 20]   ### saxonwood
        tabval[timestamp] = EventEntry(entry_type=entry_type, timestamp=timestamp, element2=element2, element3=element3,
                                       element4=element4)
                                       <...>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant