예제 #1
0
 def _parse_event_payloads(self, stream):
     (code, payload_size) = unpack('BB', stream)
     event_type = evt.EventType(code)
     if event_type is not evt.EventType.EVENT_PAYLOADS:
         raise Exception('expected event payloads, but got: %s' % event_type)
     payload_size -= 1 # includes size byte for some reason
     command_count = payload_size // 3
     if command_count * 3 != payload_size:
         raise Exception('payload size not divisible by 3: %d' % payload_size)
     payload_sizes = {}
     for i in range(command_count):
         (code, size) = unpack('BH', stream)
         payload_sizes[evt.EventType(code)] = size
     return payload_sizes
예제 #2
0
파일: game.py 프로젝트: bboss29/py-slippi
 def _parse_event(self, event_stream, payload_sizes):
     (code, ) = unpack('B', event_stream)
     try:
         event_type = evt.EventType(code)
     except ValueError:
         warn('skipping unknown event code: %d' % code)
         return None
     payload = event_stream.read(payload_sizes[event_type])
     stream = io.BytesIO(payload)
     if event_type is evt.EventType.GAME_START:
         return evt.Start._parse(stream)
     elif event_type is evt.EventType.FRAME_PRE:
         return evt.Frame.Event(evt.Frame.Event.Id(stream),
                                evt.Frame.Port.Data.Pre(stream))
     elif event_type is evt.EventType.FRAME_POST:
         return evt.Frame.Event(evt.Frame.Event.Id(stream),
                                evt.Frame.Port.Data.Post(stream))
     elif event_type is evt.EventType.GAME_END:
         return evt.End._parse(stream)
     else:
         raise Exception('unexpected event: %s' % event_type)
예제 #3
0
    def _parse_event(self, event_stream, payload_sizes):
        (code,) = unpack('B', event_stream)
        payload = event_stream.read(payload_sizes[code])
        stream = io.BytesIO(payload)

        try: event_type = evt.EventType(code)
        except ValueError: event_type = None

        if event_type is evt.EventType.GAME_START:
            return evt.Start._parse(stream)
        elif event_type is evt.EventType.FRAME_PRE:
            return evt.Frame.Event(evt.Frame.Event.Id(stream),
                                   evt.Frame.Port.Data.Pre(stream))
        elif event_type is evt.EventType.FRAME_POST:
            return evt.Frame.Event(evt.Frame.Event.Id(stream),
                                   evt.Frame.Port.Data.Post(stream))
        elif event_type is evt.EventType.GAME_END:
            return evt.End._parse(stream)
        else:
            warn('unknown event code: 0x%02x' % code)
            return None