Exemplo n.º 1
0
class StringMessage(Message):

	def getMessage(self):
		return str(self.byteBuffer.getBytes(self.msgSize));

	def buildMessage(self,messageStr):
		self.byteBuffer = ByteBuffer();
		self.byteBuffer.put(1);#magic
		self.byteBuffer.put(0);#attribute
		crcValue = binascii.crc32(messageStr);
		self.byteBuffer.putInt(crcValue);#crc32
		self.byteBuffer.putBytes(bytearray(messageStr));
		self.messageSize = len(self.byteBuffer.array());


	def toByteArray(self):
		messageByteBuffer = ByteBuffer();
		messageByteBuffer.putInt(self.messageSize);
		messageByteBuffer.putBytes(self.byteBuffer.array());
		return messageByteBuffer.array();
Exemplo n.º 2
0
class StringMessage(Message):
    def getMessage(self):
        return str(self.byteBuffer.getBytes(self.msgSize))

    def buildMessage(self, messageStr):
        self.byteBuffer = ByteBuffer()
        self.byteBuffer.put(1)
        #magic
        self.byteBuffer.put(0)
        #attribute
        crcValue = binascii.crc32(messageStr)
        self.byteBuffer.putInt(crcValue)
        #crc32
        self.byteBuffer.putBytes(bytearray(messageStr))
        self.messageSize = len(self.byteBuffer.array())

    def toByteArray(self):
        messageByteBuffer = ByteBuffer()
        messageByteBuffer.putInt(self.messageSize)
        messageByteBuffer.putBytes(self.byteBuffer.array())
        return messageByteBuffer.array()