def getBytes(self):
        constructorBytes = self.constructor.getBytes()

        sizeBytes = bytearray()
        if self.width == 1:
            sizeBytes = util.addByte(sizeBytes, self.size)
        else:
            sizeBytes = util.addInt(sizeBytes, self.size)

        countBytes = bytearray()
        if self.width == 1:
            countBytes = util.addByte(countBytes, self.count * 2)
        else:
            countBytes = util.addInt(countBytes, self.count * 2)

        valueBytes = bytearray()
        pos = 0
        if isinstance(self.map, dict):
            for key, value in self.map.items():
                if isinstance(key, TLVAmqp) and isinstance(value, TLVAmqp):
                    keyBytes = key.getBytes()
                    valBytes = value.getBytes()
                    valueBytes.append(keyBytes)
                    pos += len(keyBytes)
                    valueBytes.append(valBytes)
                    pos += len(valBytes)

        data = bytearray()
        data.append(constructorBytes)
        if self.size > 0:
            data += sizeBytes
            data += countBytes
            data += valueBytes
        return data
    def getBytes(self):
        constructorBytes = self.constructor.getBytes()

        sizeBytes = bytearray()
        if self.width == 1:
            sizeBytes = util.addByte(sizeBytes, self.size)
        elif self.width == 4:
            sizeBytes = util.addInt(sizeBytes, self.size)

        countBytes = bytearray()
        if self.width == 1:
            countBytes = util.addByte(countBytes, self.count)
        elif self.width != 0 and self.width == 4:
            countBytes = util.addInt(countBytes, self.count)

        elementConstructorBytes = self.elementConstructor.getBytes()
        valueBytes = bytearray()
        pos = 0
        for tlv in self.values:
            if isinstance(tlv, TLVAmqp):
                tlvBytes = tlv.getBytes()
                valueBytes += tlvBytes[1:len(tlvBytes)]
                pos += len(tlvBytes) - len(str(elementConstructorBytes)) - 1
        data = bytearray()
        data.append(constructorBytes)
        if self.size > 0:
            data += sizeBytes
            data += countBytes
            data = util.addByte(data, elementConstructorBytes)
            data += valueBytes
        return data
Exemplo n.º 3
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
 def encode(self):
     arr = bytearray()
     mf = bytearray()
     mf = util.addInt(mf, self.getMessageFormat())
     arr += mf[1:4]
     arr = util.addByte(arr, self.getVersion())
     return np.int64(util.getInt(arr))
 def convertUInt(self, i):
     data = bytearray()
     if i == 0:
         return data
     elif i > 0 and i <= 255:
         data = util.addByte(data, i)
         return data
     else:
         data = util.addInt(data, i)
         return data
Exemplo n.º 6
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 getBytes(self):
        constructorBytes = self.constructor.getBytes()

        sizeBytes = bytearray()
        if self.width == 1:
            sizeBytes = util.addByte(sizeBytes, self.size)
        elif self.width != 0:
            sizeBytes = util.addInt(sizeBytes, self.size)

        countBytes = bytearray()
        if self.width == 1:
            countBytes = util.addByte(countBytes, self.count)
        elif self.width != 0:
            countBytes = util.addInt(countBytes, self.count)

        valueBytes = bytearray()
        pos = 0
        if self.values is not None:
            for tlv in self.values:
                if isinstance(tlv, TLVAmqp):
                    tlvBytes = tlv.getBytes()

                    if isinstance(tlvBytes, int):
                        valueBytes = util.addByte(valueBytes, tlvBytes)
                        pos += 1
                    else:
                        valueBytes += tlvBytes
                        pos += len(tlvBytes)

        data = bytearray()
        data += constructorBytes
        if self.size > 0:
            data += sizeBytes
            data += countBytes
            data += valueBytes
        return 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