def EncodeElement(self, array, index, buffer): theLong = array[index] if (-0X7FFFFFFF <= theLong <= 0X7FFFFFFF): _IPC.formatPutInt(buffer, theLong) # 8 byte longs not implemented, yet #elif (0 <= theLong < 0XFFFFFFFFFFFFFFFF) : # _IPC.formatPutLong(buffer, theLong) else: Raise("Will lose precision in transferring long: %d" % theLong)
def Encode(self, dataStruct, dstart, buffer): theLong = getLongField(dataStruct, dstart) if (-0X7FFFFFFF <= theLong <= 0X7FFFFFFF): _IPC.formatPutInt(buffer, theLong) # 8 byte longs not implemented, yet #elif (0 <= theLong < 0XFFFFFFFFFFFFFFFF) : # _IPC.formatPutLong(buffer, theLong) else: Raise("Will lose precision in transferring long: %d" % theLong)
def EncodeElement(self, array, index, buffer) : theLong = array[index] if (-0X7FFFFFFF <= theLong <= 0X7FFFFFFF) : _IPC.formatPutInt(buffer, theLong) # 8 byte longs not implemented, yet #elif (0 <= theLong < 0XFFFFFFFFFFFFFFFF) : # _IPC.formatPutLong(buffer, theLong) else : Raise("Will lose precision in transferring long: %d" % theLong)
def Encode (self, dataStruct, dstart, buffer) : theLong = getLongField(dataStruct, dstart) if (-0X7FFFFFFF <= theLong <= 0X7FFFFFFF) : _IPC.formatPutInt(buffer, theLong) # 8 byte longs not implemented, yet #elif (0 <= theLong < 0XFFFFFFFFFFFFFFFF) : # _IPC.formatPutLong(buffer, theLong) else : Raise("Will lose precision in transferring long: %d" % theLong)
def transferToBuffer(format, dataStruct, dStart, buffer, parentFormat, isTopLevelStruct): ftype = _IPC.formatType(format) if (ftype == LengthFMT): IPC.Raise("Python version of IPC can only use explicit formats") elif (ftype == PrimitiveFMT): if (isTopLevelStruct): object = IPCdata() object._f0 = dataStruct dataStruct = object primFmttrs.Encode(_IPC.formatPrimitiveProc(format), dataStruct, dStart, buffer) elif (ftype == PointerFMT): object = primFmttrs.getObjectField(dataStruct, dStart) # 'Z' means data, 0 means NIL if (object is None): theChar = '\0' else: theChar = 'Z' _IPC.formatPutChar(buffer, theChar) if (not object is None): transferToBuffer(_IPC.formatChoosePtrFormat(format, parentFormat), dataStruct, dStart, buffer, 0, isTopLevelStruct) elif (ftype == StructFMT): formatArray = _IPC.formatFormatArray(format) structStart = 0 n = _IPC.formatFormatArrayMax(formatArray) if (isTopLevelStruct): struct = dataStruct else: struct = primFmttrs.getObjectField(dataStruct, dStart) for i in range(1, n): transferToBuffer(_IPC.formatFormatArrayItemPtr(formatArray, i), struct, structStart, buffer, format, False) structStart = structStart + 1 elif (ftype == FixedArrayFMT): formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) if (isTopLevelStruct): arrayObject = dataStruct else: arrayObject = primFmttrs.getObjectField(dataStruct, dStart) if (not isinstance(arrayObject, (tuple, list))): IPC.Raise(invalidArrayFormat(dataStruct, dStart)) else: arrayTransferToBuffer(arrayObject, buffer, 2, _IPC.formatFormatArrayMax(formatArray) - 1, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, False) elif (ftype == VarArrayFMT): formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) if (isTopLevelStruct): arrayObject = dataStruct else: arrayObject = primFmttrs.getObjectField(dataStruct, dStart) # For the size of the array _IPC.formatPutInt(buffer, varArrayNumElements(formatArray, dataStruct)) if (not isinstance(arrayObject, (tuple, list))): IPC.Raise(invalidArrayFormat(dataStruct, dStart)) else: arrayTransferToBuffer(arrayObject, buffer, 2, _IPC.formatFormatArrayMax(formatArray) - 1, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, True) elif (ftype == NamedFMT): transferToBuffer(_IPC.findNamedFormat(format), dataStruct, dStart, buffer, parentFormat, isTopLevelStruct) elif (ftype == EnumFMT): primFmttrs.Encode(primFmttrs.INT_FMT, dataStruct, dStart, buffer) else: IPC.Raise("Unhandled format: %s" % ftype)
def transferToBuffer (format, dataStruct, dStart, buffer, parentFormat, isTopLevelStruct) : ftype = _IPC.formatType(format) if (ftype == LengthFMT) : IPC.Raise("Python version of IPC can only use explicit formats") elif (ftype == PrimitiveFMT) : if (isTopLevelStruct) : object = IPCdata() object._f0 = dataStruct dataStruct = object primFmttrs.Encode(_IPC.formatPrimitiveProc(format), dataStruct, dStart, buffer) elif (ftype == PointerFMT) : object = primFmttrs.getObjectField(dataStruct, dStart) # 'Z' means data, 0 means NIL if (object is None) : theChar = '\0' else : theChar = 'Z' _IPC.formatPutChar(buffer, theChar); if (not object is None) : transferToBuffer(_IPC.formatChoosePtrFormat(format, parentFormat), dataStruct, dStart, buffer, 0, isTopLevelStruct) elif (ftype == StructFMT) : formatArray = _IPC.formatFormatArray(format) structStart = 0 n = _IPC.formatFormatArrayMax(formatArray) if (isTopLevelStruct) : struct = dataStruct else : struct = primFmttrs.getObjectField(dataStruct, dStart) for i in range(1, n) : transferToBuffer(_IPC.formatFormatArrayItemPtr(formatArray, i), struct, structStart, buffer, format, False) structStart = structStart + 1 elif (ftype == FixedArrayFMT) : formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) if (isTopLevelStruct) : arrayObject = dataStruct else : arrayObject = primFmttrs.getObjectField(dataStruct, dStart) if (not isinstance(arrayObject, (tuple, list))) : IPC.Raise(invalidArrayFormat(dataStruct, dStart)) else : arrayTransferToBuffer(arrayObject, buffer, 2, _IPC.formatFormatArrayMax(formatArray)-1, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, False); elif (ftype == VarArrayFMT) : formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) if (isTopLevelStruct) : arrayObject = dataStruct else : arrayObject = primFmttrs.getObjectField(dataStruct, dStart) # For the size of the array _IPC.formatPutInt(buffer, varArrayNumElements(formatArray, dataStruct)) if (not isinstance(arrayObject, (tuple, list))) : IPC.Raise(invalidArrayFormat(dataStruct, dStart)) else : arrayTransferToBuffer(arrayObject, buffer, 2, _IPC.formatFormatArrayMax(formatArray)-1, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, True) elif (ftype == NamedFMT) : transferToBuffer(_IPC.findNamedFormat(format), dataStruct, dStart, buffer, parentFormat, isTopLevelStruct) elif (ftype == EnumFMT) : primFmttrs.Encode(primFmttrs.INT_FMT, dataStruct, dStart, buffer); else : IPC.Raise("Unhandled format: %s" % ftype)
def EncodeElement(self, array, index, buffer): _IPC.formatPutInt(buffer, array[index])
def Encode(self, dataStruct, dstart, buffer): _IPC.formatPutInt(buffer, getIntField(dataStruct, dstart))
def EncodeElement(self, array, index, buffer) : _IPC.formatPutInt(buffer, array[index])
def Encode (self, dataStruct, dstart, buffer) : _IPC.formatPutInt(buffer, getIntField(dataStruct, dstart))