def _from_response(self, data): if len(data) != 16: raise DecodingError('Invalid SEL record length (%d)' % len(data)) self.data = data # pop will change data, therefore copy it buffer = ByteBuffer(data) self.record_id = buffer.pop_unsigned_int(2) self.type = buffer.pop_unsigned_int(1) if (self.type != self.TYPE_SYSTEM_EVENT and self.type not in self.TYPE_OEM_TIMESTAMPED_RANGE and self.type not in self.TYPE_OEM_NON_TIMESTAMPED_RANGE): raise DecodingError('Unknown SEL type (0x%02x)' % self.type) self.timestamp = buffer.pop_unsigned_int(4) self.generator_id = buffer.pop_unsigned_int(2) self.evm_rev = buffer.pop_unsigned_int(1) self.sensor_type = buffer.pop_unsigned_int(1) self.sensor_number = buffer.pop_unsigned_int(1) event_desc = buffer.pop_unsigned_int(1) if event_desc & 0x80: self.event_direction = EVENT_DEASSERTION else: self.event_direction = EVENT_ASSERTION self.event_type = event_desc & 0x3f self.event_data = buffer.pop_string(3)
def from_response(self, data): if len(data) != 16: raise DecodingError('Invalid SEL record length (%d)' % len(data)) self.data = data # pop will change data, therefore copy it buffer = ByteBuffer(data) self.record_id = buffer.pop_unsigned_int(2) self.type = buffer.pop_unsigned_int(1) if (self.type != self.TYPE_SYSTEM_EVENT and self.type not in self.TYPE_OEM_TIMESTAMPED_RANGE and self.type not in self.TYPE_OEM_NON_TIMESTAMPED_RANGE): raise DecodingError('Unknown SEL type (0x%02x)' % self.type) self.timestamp = buffer.pop_unsigned_int(4) self.generator_id = buffer.pop_unsigned_int(2) self.evm_rev = buffer.pop_unsigned_int(1) self.sensor_type = buffer.pop_unsigned_int(1) self.sensor_number = buffer.pop_unsigned_int(1) event_desc = buffer.pop_unsigned_int(1) if event_desc & 0x80: self.event_direction = EVENT_DEASSERTION else: self.event_direction = EVENT_ASSERTION self.event_type = event_desc & 0x3f self.event_data = buffer.pop_string(3)
def test_bytebuffer_pop_string(): buf = ByteBuffer(b'\x30\x31\x32\x33') eq_(buf.pop_string(2), b'01') eq_(buf.tostring(), b'23')