示例#1
0
    def encode(self, header):
        buf = None

        if isinstance(header,AMQPProtoHeader):
            buf = bytearray()
            buf = util.addString(buf,'AMQP')
            buf = util.addByte(buf,header.getProtocolId())
            buf = util.addByte(buf, header.getVersionMajor())
            buf = util.addByte(buf, header.getVersionMinor())
            buf = util.addByte(buf, header.getVersionRevision())
            return buf

        if isinstance(header,AMQPPing):
            buf = bytearray()
            buf = util.addInt(buf,8)
            buf = util.addByte(buf,header.getDoff())
            buf = util.addByte(buf, header.getType())
            buf = util.addShort(buf, header.getChannel())
            return buf

        length = 8
        if isinstance(header,AMQPHeader):
            arguments = header.toArgumentsList()
            length += arguments.getLength()

        sections = None

        if header.getCode() == HeaderCode.TRANSFER and isinstance(header,AMQPTransfer):
            sections = header.getSections()
            if sections is not None and isinstance(sections,dict):
                for section in sections.values():
                    if isinstance(section, AMQPSection):
                        length += section.getValue().getLength()

        buf = bytearray()
        buf = util.addInt(buf,length)
        buf = util.addByte(buf,header.getDoff())
        buf = util.addByte(buf, header.getType())
        buf = util.addShort(buf, header.getChannel())

        if isinstance(arguments,TLVList):
            buf += arguments.getBytes()

        if sections is not None and isinstance(sections,dict):
            for section in sections.values():
                if isinstance(section, AMQPSection):
                    value = section.getValue()
                    if isinstance(value, TLVAmqp):
                        buf += value.getBytes()

        self.index = 0
        return buf
 def wrapUShort(self, sh):
     if sh < 0:
         raise ValueError('negative value of ' + str(sh) +
                          ' cannot be assignet to UShort type')
     data = bytearray()
     data = util.addShort(data, sh)
     return TLVFixed(AMQPType.USHORT, data)
 def __init__(self, value):
     data = bytearray()
     if isinstance(value, bytearray):
         data = value
     if isinstance(value, np.int8):
         data = util.addByte(data, value)
     if isinstance(value, np.int16):
         data = util.addShort(data, value)
     if isinstance(value, np.int32):
         data = util.addInt(data, value)
     if isinstance(value, np.int64):
         data = util.addLong(data, value)
     if isinstance(value, np.float32):
         data = util.addFloat(data, value)
     if isinstance(value, np.complex128):
         data = util.addDouble(data, value)
     self.value = data
 def wrapShort(self, sh):
     data = bytearray()
     data = util.addShort(data, sh)
     return TLVFixed(AMQPType.USHORT, data)