def test_parsing(self): length_bytes = [0x01] length = Length.parse(ConstBitStream(bytes=length_bytes)) self.assertEqual(length.value, 1) length_bytes = [0x40, 0x41] length = Length.parse(ConstBitStream(bytes=length_bytes)) self.assertEqual(length.value, 65) length_bytes = [0xC0, 0x41, 0x10, 0x00] length = Length.parse(ConstBitStream(bytes=length_bytes)) self.assertEqual(length.value, 4263936)
def parse(s): type = QueryType(s.read("uint:3")) assert (type == QueryType.ARITH_COMP_WITH_VALUE ) # TODO implement other types mask_present = s.read("bool") assert (mask_present is False) # TODO implement this params = ArithQueryParams.parse(s) compare_length = Length.parse(s) compare_value = map(ord, s.read("bytes:" + str(compare_length.value))) file_a_offset = Offset.parse(s) return QueryOperand(type=type, mask_present=mask_present, params=params, compare_length=compare_length, compare_value=compare_value, file_a_offset=file_a_offset)
def parse(s): id = s.read("uint:8") offset = Length.parse(s) return Offset(id=id, offset=offset)
def parse_alp_return_file_data_operand(self, s): offset = self.parse_offset(s) length = Length.parse(s) data = s.read("bytes:" + str(length.value)) return Data(offset=offset, data=map(ord, data))
def parse_alp_file_data_request_operand(self, s): offset = self.parse_offset(s) length = Length.parse(s) return DataRequest(length=length.value, offset=offset)