Example #1
0
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)
Example #2
0
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)
Example #3
0
 def EncodeElement(self, array, index, buffer):
     _IPC.formatPutChar(buffer, array[index])
Example #4
0
 def Encode(self, dataStruct, dstart, buffer):
     _IPC.formatPutChar(buffer, getCharField(dataStruct, dstart))
Example #5
0
 def EncodeElement(self, array, index, buffer) : 
   _IPC.formatPutChar(buffer, array[index])
Example #6
0
 def Encode (self, dataStruct, dstart, buffer) :
   _IPC.formatPutChar(buffer, getCharField(dataStruct, dstart))