def transferToDataStructure(format, dataStruct, dStart, buffer, parentFormat, isTopLevelStruct, oclass=None): ftype = _IPC.formatType(format) if (ftype == LengthFMT): IPC.Raise("Python version of IPC can only use explicit formats") elif (ftype == PrimitiveFMT): try: dataStruct.__dict__ # Is this a settable object except AttributeError: IPC.Raise( invalidStructFormat( type(dataStruct), primFmttrs.PrimType(_IPC.formatPrimitiveProc(format)))) primFmttrs.Decode(_IPC.formatPrimitiveProc(format), dataStruct, dStart, buffer) elif (ftype == PointerFMT): theChar = _IPC.formatGetChar(buffer) if (theChar == '\0'): primFmttrs.setObjectField(dataStruct, dStart, None) else: transferToDataStructure( _IPC.formatChoosePtrFormat(format, parentFormat), dataStruct, dStart, buffer, 0, isTopLevelStruct, oclass) elif (ftype == StructFMT): formatArray = _IPC.formatFormatArray(format) structStart = 0 n = _IPC.formatFormatArrayMax(formatArray) if (isTopLevelStruct): struct = dataStruct else: struct1 = primFmttrs.getObjectField(dataStruct, dStart) struct = validateObject(struct1, dataStruct, dStart) if (not struct == struct1): primFmttrs.setObjectField(dataStruct, dStart, struct) for i in range(1, n): transferToDataStructure( _IPC.formatFormatArrayItemPtr(formatArray, i), struct, structStart, buffer, format, False) structStart = structStart + 1 elif (ftype == FixedArrayFMT): formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) size = _IPC.formatFormatArrayItemInt(formatArray, 2) if (isTopLevelStruct and isinstance(dataStruct, (tuple, list))): arrayObject = dataStruct else: arrayObject = primFmttrs.getObjectField(dataStruct, dStart) arrayObject = validateArrayObject(arrayObject, size, dataStruct, dStart) primFmttrs.setObjectField(dataStruct, dStart, arrayObject) arrayTransferToDataStructure( arrayObject, buffer, 2, _IPC.formatFormatArrayMax(formatArray) - 1, size, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, dStart, False, oclass) elif (ftype == VarArrayFMT): formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) # The total size of the array is the stored first size = _IPC.formatGetInt(buffer) numDims = _IPC.formatFormatArrayMax(formatArray) - 2 if (numDims > 1): size = varArrayDimSize(2, formatArray, dataStruct) if (not feasibleToDecodeVarArray(size, formatArray, dStart)): IPC.Raise("Python version of IPC cannot decode " + \ "multi-dimensional variable length arrays unless " + \ "the size variables appear BEFORE the array " + \ "in the enclosing structure") elif (isTopLevelStruct): arrayObject = dataStruct else: arrayObject = primFmttrs.getObjectField(dataStruct, dStart) arrayObject = validateArrayObject(arrayObject, size, dataStruct, dStart) primFmttrs.setObjectField(dataStruct, dStart, arrayObject) arrayTransferToDataStructure(arrayObject, buffer, 2, numDims + 1, size, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, dStart, True, oclass) elif (ftype == NamedFMT): transferToDataStructure(_IPC.findNamedFormat(format), dataStruct, dStart, buffer, parentFormat, isTopLevelStruct) elif (ftype == EnumFMT): primFmttrs.Decode(primFmttrs.INT_FMT, dataStruct, dStart, buffer) else: IPC.Raise("Unhandled format: %s" % ftype)
def transferToDataStructure (format, dataStruct, dStart, buffer, parentFormat, isTopLevelStruct, oclass=None) : ftype = _IPC.formatType(format) if (ftype == LengthFMT) : IPC.Raise("Python version of IPC can only use explicit formats") elif (ftype == PrimitiveFMT) : try: dataStruct.__dict__ # Is this a settable object except AttributeError: IPC.Raise(invalidStructFormat(type(dataStruct), primFmttrs.PrimType(_IPC.formatPrimitiveProc(format)))) primFmttrs.Decode(_IPC.formatPrimitiveProc(format), dataStruct, dStart, buffer) elif (ftype == PointerFMT) : theChar = _IPC.formatGetChar(buffer) if (theChar == '\0') : primFmttrs.setObjectField(dataStruct, dStart, None) else : transferToDataStructure(_IPC.formatChoosePtrFormat(format, parentFormat), dataStruct, dStart, buffer, 0, isTopLevelStruct, oclass) elif (ftype == StructFMT) : formatArray = _IPC.formatFormatArray(format) structStart = 0 n = _IPC.formatFormatArrayMax(formatArray) if (isTopLevelStruct) : struct = dataStruct else : struct1 = primFmttrs.getObjectField(dataStruct, dStart) struct = validateObject(struct1, dataStruct, dStart) if (not struct == struct1) : primFmttrs.setObjectField(dataStruct, dStart, struct) for i in range(1, n) : transferToDataStructure(_IPC.formatFormatArrayItemPtr(formatArray, i), struct, structStart, buffer, format, False) structStart = structStart + 1 elif (ftype == FixedArrayFMT) : formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) size = _IPC.formatFormatArrayItemInt(formatArray, 2) if (isTopLevelStruct and isinstance(dataStruct, (tuple, list))) : arrayObject = dataStruct; else : arrayObject = primFmttrs.getObjectField(dataStruct, dStart) arrayObject = validateArrayObject(arrayObject, size, dataStruct, dStart) primFmttrs.setObjectField(dataStruct, dStart, arrayObject) arrayTransferToDataStructure(arrayObject, buffer, 2, _IPC.formatFormatArrayMax(formatArray)-1, size, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, dStart, False, oclass); elif (ftype == VarArrayFMT) : formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) # The total size of the array is the stored first size = _IPC.formatGetInt(buffer) numDims = _IPC.formatFormatArrayMax(formatArray) - 2 if (numDims > 1) : size = varArrayDimSize(2, formatArray, dataStruct) if (not feasibleToDecodeVarArray(size, formatArray, dStart)) : IPC.Raise("Python version of IPC cannot decode " + \ "multi-dimensional variable length arrays unless " + \ "the size variables appear BEFORE the array " + \ "in the enclosing structure") elif (isTopLevelStruct) : arrayObject = dataStruct else : arrayObject = primFmttrs.getObjectField(dataStruct, dStart) arrayObject = validateArrayObject(arrayObject, size, dataStruct, dStart) primFmttrs.setObjectField(dataStruct, dStart, arrayObject) arrayTransferToDataStructure(arrayObject, buffer, 2, numDims+1, size, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, dStart, True, oclass) elif (ftype == NamedFMT) : transferToDataStructure(_IPC.findNamedFormat(format), dataStruct, dStart, buffer, parentFormat, isTopLevelStruct) elif (ftype == EnumFMT) : primFmttrs.Decode(primFmttrs.INT_FMT, dataStruct, dStart, buffer) else : IPC.Raise("Unhandled format: %s" % ftype)
def DecodeElement(self, array, index, buffer): array[index] = _IPC.formatGetChar(buffer)
def Decode(self, dataStruct, dstart, buffer): setCharField(dataStruct, dstart, _IPC.formatGetChar(buffer))
def DecodeElement(self, array, index, buffer) : array[index] = _IPC.formatGetChar(buffer)
def Decode (self, dataStruct, dstart, buffer) : setCharField(dataStruct, dstart, _IPC.formatGetChar(buffer))