def read_data(data): ba = ByteArray(data) #大端模式标准对齐方式 ba.endian = "!" length = ba.readInt() print "length", length print "bytesAvailable", ba.bytesAvailable() #只用了1位字节存储 长度-128 - 127 #业务大类 actionName = ba.readByte() #具体业务类型 type = ba.readByte() print "actionName", actionName print "type", type str = ba.readUTFBytes(3) print str i = ba.readInt() print i
def dataReceived(self, data): ba = ByteArray(data) print ba.bytesAvailable() s = ba.readUnsignedInt() print ba.bytesAvailable() print s s = ba.readUTFBytes(ba.bytesAvailable()) print s
def lineReceived(self, line): print line ba = ByteArray(line) print ba.bytesAvailable() s = ba.readInt() print s s = ba.readUTFBytes(ba.bytesAvailable()) print s self.factory.sendAll(self, line)
def decode(self, data): ba = ByteArray(data) ba.endian = "!" #判断长度 #print 'self.tempDataBuffer', self.tempDataBuffer if self.tempDataBuffer == "": self.id = ba.readInt() print self.id length = ba.readInt() s = ba.readUTFBytes(ba.bytesAvailable()) print 'length', length, len(s) #判断长度 if len(s) < length: self.tempDataBuffer = s else: print "content", s return {"id": self.id, "content": s} else: s = self.tempDataBuffer + ba.readUTFBytes(ba.bytesAvailable()) print 'hebing', s return {"id": self.id, "content": s}
def decode(self, data): ba = ByteArray(data) ba.endian = "!" #判断长度 #print 'self.tempDataBuffer', self.tempDataBuffer if self.tempDataBuffer == "": self.id = ba.readInt() print self.id length = ba.readInt() s = ba.readUTFBytes(ba.bytesAvailable()) print 'length', length, len(s) #判断长度 if len(s) < length: self.tempDataBuffer = s else: print "content", s return {"id":self.id, "content":s} else: s = self.tempDataBuffer + ba.readUTFBytes(ba.bytesAvailable()) print 'hebing', s return {"id":self.id, "content":s}