def _test_packed_array_auto(self, array_traits, array_values, expected_bitsize): for i in range(8): array = Array(array_traits, array_values, is_auto=True) bitsize = array.bitsizeof_packed(i) if expected_bitsize is not None: self.assertEqual(expected_bitsize, bitsize) self.assertEqual(i + bitsize, array.initialize_offsets_packed(i), i) writer = BitStreamWriter() if i > 0: writer.write_bits(0, i) array.write_packed(writer) self.assertEqual(i + bitsize, writer.bitposition, i) from_reader = BitStreamReader(writer.byte_array, writer.bitposition) self.assertEqual(0, from_reader.read_bits(i)) read_array_from_reader = Array.from_reader_packed(array_traits, from_reader, is_auto=True) self.assertEqual(array, read_array_from_reader, i) reader = BitStreamReader(writer.byte_array, writer.bitposition) if i > 0: self.assertEqual(0, reader.read_bits(i)) read_array = Array(array_traits, is_auto=True) read_array.read_packed(reader) self.assertEqual(array, read_array, i)
def _test_packed_array_aligned(self, array_traits, array_values, expected_bitsize): for i in range(8): array = Array(array_traits, array_values, set_offset_method=ArrayTest._set_offset_method, check_offset_method=ArrayTest._check_offset_method) bitsize = array.bitsizeof_packed(i) if expected_bitsize is not None and i == 0: self.assertEqual(expected_bitsize, bitsize) self.assertEqual(i + bitsize, array.initialize_offsets_packed(i), i) writer = BitStreamWriter() if i > 0: writer.write_bits(0, i) array.write_packed(writer) self.assertEqual(i + bitsize, writer.bitposition, i) from_reader = BitStreamReader(writer.byte_array, writer.bitposition) self.assertEqual(0, from_reader.read_bits(i)) read_array_from_reader = Array.from_reader_packed( array_traits, from_reader, len(array_values), set_offset_method=ArrayTest._set_offset_method, check_offset_method=ArrayTest._check_offset_method) self.assertEqual(array, read_array_from_reader, i) reader = BitStreamReader(writer.byte_array, writer.bitposition) if i > 0: self.assertEqual(0, reader.read_bits(i)) read_array = Array( array_traits, set_offset_method=ArrayTest._set_offset_method, check_offset_method=ArrayTest._check_offset_method) read_array.read_packed(reader, len(array_values)) self.assertEqual(array, read_array, i)