コード例 #1
0
 def getBytes(self):
     data = bytearray()
     data = util.addString(data, self.protocol)
     data = util.addByte(self.protocolId)
     data = util.addByte(self.versionMajor)
     data = util.addByte(self.versionMinor)
     data = util.addByte(self.versionRevision)
     return data
コード例 #2
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