def testExternArrays(self): arraysMapping = self.api.ArraysMapping() externArray = [ zserio.BitBuffer(bytes([0xCD, 0x03]), 10) for i in range(self.FIXED_ARRAY_LENGTH) ] arraysMapping.setExternArray(externArray)
def testReadWrite(self): allBuiltInTypes = self.api.AllBuiltInTypes() allBuiltInTypes.setBoolType(True) allBuiltInTypes.setUint8Type(8) allBuiltInTypes.setUint16Type(zserio.limits.UINT16_MAX) allBuiltInTypes.setUint32Type(zserio.limits.UINT32_MAX) allBuiltInTypes.setUint64Type(zserio.limits.UINT64_MAX) allBuiltInTypes.setInt8Type(zserio.limits.INT8_MAX) allBuiltInTypes.setInt16Type(zserio.limits.INT16_MAX) allBuiltInTypes.setInt32Type(zserio.limits.INT32_MAX) allBuiltInTypes.setInt64Type(zserio.limits.INT64_MAX) allBuiltInTypes.setBitfield7Type(0x7F) allBuiltInTypes.setBitfield8Type(zserio.limits.UINT8_MAX) allBuiltInTypes.setBitfield15Type(0x7FFF) allBuiltInTypes.setBitfield16Type(zserio.limits.UINT16_MAX) allBuiltInTypes.setBitfield31Type(0x7FFFFFFF) allBuiltInTypes.setBitfield32Type(zserio.limits.UINT32_MAX) allBuiltInTypes.setBitfield63Type(0x7FFFFFFFFFFFFFFF) allBuiltInTypes.setVariableBitfieldType(zserio.limits.UINT8_MAX) allBuiltInTypes.setVariableBitfield8Type(zserio.limits.UINT8_MAX) allBuiltInTypes.setIntfield8Type(zserio.limits.INT8_MAX) allBuiltInTypes.setIntfield16Type(zserio.limits.INT16_MAX) allBuiltInTypes.setIntfield32Type(zserio.limits.INT32_MAX) allBuiltInTypes.setIntfield64Type(zserio.limits.INT64_MAX) allBuiltInTypes.setVariableIntfieldType(zserio.limits.INT8_MAX) allBuiltInTypes.setVariableIntfield8Type(zserio.limits.INT8_MAX) allBuiltInTypes.setFloat16Type(1.0) allBuiltInTypes.setFloat32Type(1.0) allBuiltInTypes.setFloat64Type(sys.float_info.max) allBuiltInTypes.setVaruint16Type(zserio.limits.VARUINT16_MAX) allBuiltInTypes.setVaruint32Type(zserio.limits.VARUINT32_MAX) allBuiltInTypes.setVaruint64Type(zserio.limits.VARUINT64_MAX) allBuiltInTypes.setVaruintType(zserio.limits.VARUINT_MAX) allBuiltInTypes.setVarint16Type(zserio.limits.VARINT16_MAX) allBuiltInTypes.setVarint32Type(zserio.limits.VARINT32_MAX) allBuiltInTypes.setVarint64Type(zserio.limits.VARINT64_MAX) allBuiltInTypes.setVarintType(zserio.limits.VARINT_MAX) allBuiltInTypes.setStringType("TEST") allBuiltInTypes.setExternType(zserio.BitBuffer(bytes([0xCD, 0x03]), 10)) writer = zserio.BitStreamWriter() allBuiltInTypes.write(writer) reader = zserio.BitStreamReader(writer.getByteArray()) readAllBuiltInTypes = self.api.AllBuiltInTypes() readAllBuiltInTypes.read(reader) self.assertEqual(allBuiltInTypes, readAllBuiltInTypes)
def testBitSizeOf(self): allBuiltInTypes = self.api.AllBuiltInTypes() allBuiltInTypes.setBoolType(True) allBuiltInTypes.setUint8Type(1) allBuiltInTypes.setUint16Type(zserio.limits.UINT16_MAX) allBuiltInTypes.setUint32Type(zserio.limits.UINT32_MAX) allBuiltInTypes.setUint64Type(zserio.limits.UINT64_MAX) allBuiltInTypes.setInt8Type(zserio.limits.INT8_MAX) allBuiltInTypes.setInt16Type(zserio.limits.INT16_MAX) allBuiltInTypes.setInt32Type(zserio.limits.INT32_MAX) allBuiltInTypes.setInt64Type(zserio.limits.INT64_MAX) allBuiltInTypes.setBitfield7Type(0x7F) allBuiltInTypes.setBitfield8Type(zserio.limits.UINT8_MAX) allBuiltInTypes.setBitfield15Type(0x7FFF) allBuiltInTypes.setBitfield16Type(zserio.limits.UINT16_MAX) allBuiltInTypes.setBitfield31Type(0x7FFFFFFF) allBuiltInTypes.setBitfield32Type(zserio.limits.UINT32_MAX) allBuiltInTypes.setBitfield63Type(0x7FFFFFFFFFFFFFFF) allBuiltInTypes.setVariableBitfieldType(1) allBuiltInTypes.setVariableBitfield8Type(zserio.limits.UINT8_MAX) allBuiltInTypes.setIntfield8Type(zserio.limits.INT8_MAX) allBuiltInTypes.setIntfield16Type(zserio.limits.INT16_MAX) allBuiltInTypes.setIntfield32Type(zserio.limits.INT32_MAX) allBuiltInTypes.setIntfield64Type(zserio.limits.INT64_MAX) allBuiltInTypes.setVariableIntfieldType(1) allBuiltInTypes.setVariableIntfield8Type(zserio.limits.INT8_MAX) allBuiltInTypes.setFloat16Type(sys.float_info.max) allBuiltInTypes.setFloat32Type(sys.float_info.max) allBuiltInTypes.setFloat64Type(sys.float_info.max) allBuiltInTypes.setVaruint16Type(zserio.limits.VARUINT16_MAX) allBuiltInTypes.setVaruint32Type(zserio.limits.VARUINT32_MAX) allBuiltInTypes.setVaruint64Type(zserio.limits.VARUINT64_MAX) allBuiltInTypes.setVaruintType(zserio.limits.VARUINT_MAX) allBuiltInTypes.setVarint16Type(zserio.limits.VARINT16_MAX) allBuiltInTypes.setVarint32Type(zserio.limits.VARINT32_MAX) allBuiltInTypes.setVarint64Type(zserio.limits.VARINT64_MAX) allBuiltInTypes.setVarintType(zserio.limits.VARINT_MAX) allBuiltInTypes.setStringType("TEST") allBuiltInTypes.setExternType(zserio.BitBuffer(bytes([0xCD, 0x03]), 10)) expectedBitSizeOf = 1102 self.assertEqual(expectedBitSizeOf, allBuiltInTypes.bitSizeOf())
def _createTestStructure(self, index): name = "name" + str(index) data = zserio.BitBuffer(bytes([0xCD, 0xC0]), 10) testChoice = ( self.api.TestChoice(index, value16_=index) if index in (0, 2, 4) else self.api.TestChoice(index, array32_=[index * 2, index * 2 + 1]) if index == 5 else self.api.TestChoice(index, value32_=self.api.Value32(index * 2))) testUnion = (self.api.TestUnion(value16_=index) if (index % 2) == 0 else self.api.TestUnion( array32_=[index * 2, index * 2 + 1]) if index == 5 else self.api.TestUnion( value32_=self.api.Value32(index * 2))) testEnum = self.api.TestEnum.DARK_RED if ( index % 2) == 0 else self.api.TestEnum.DARK_GREEN testBitmask = (self.api.TestBitmask.Values.READ if (index % 2) == 0 else self.api.TestBitmask.Values.CREATE) testOptional = index if (index % 2) == 0 else None testDynamicBitfield = index % 3 values = list(range(1, 18, 3)) numValues = len(values) empties = [self.api.Empty()] * numValues return self.api.TestStructure( id_=index, name_=name, data_=data, test_choice_=testChoice, test_union_=testUnion, test_enum_=testEnum, test_bitmask_=testBitmask, test_optional_=testOptional, test_dynamic_bitfield_=testDynamicBitfield, num_values_=numValues, unpacked_values_=values, packed_values_=values, packed_empties_=empties)
def testExternType(self): allBuiltInTypes = self.api.AllBuiltInTypes() testExtern = zserio.BitBuffer(bytes([0xCD, 0x03]), 10) allBuiltInTypes.setExternType(testExtern) self.assertEqual(testExtern, allBuiltInTypes.getExternType())
def _getExternalBitBuffer(self): externalStructure = self.api.ExternalStructure.fromFields(0xCD, 0x03) writer = zserio.BitStreamWriter() externalStructure.write(writer) return zserio.BitBuffer(writer.getByteArray(), writer.getBitPosition())
def _createPackedAutoArray(self): return self.api.PackedAutoArray( [self.api.TestStructure(uint32, zserio.BitBuffer(extern), uint8) for uint32, extern, uint8 in zip(self.UINT32_FIELD, self.EXTERN_FIELD, self.UINT8_FIELD)] )
def _getExternalBitBuffer(self): externalStructure = self.api.ExternalStructure(value_=0xCD, rest_=0x03) writer = zserio.BitStreamWriter() externalStructure.write(writer) return zserio.BitBuffer(writer.byte_array, writer.bitposition)