Skip to content

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

Description

@SaxonWood

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)
                                       <...>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions