private ResponseMessage Decode(Stream responseStream) { ByteBuffer buffer = ByteBuffer.Allocate(512); byte[] tempBytes = new byte[256]; while (true) { int readLen = responseStream.Read(tempBytes, 0, tempBytes.Length); if (readLen <= 0) { break; } buffer.WriteBytes(tempBytes); } ResponseMessage responseMessage = new ResponseMessage(); responseMessage.MessageId = buffer.ReadInt(); responseMessage.StatusCode = HttpStatusCode.OK; TBase message = ThriftMessageHelper.GetResponseMessage(responseMessage.MessageId); if (message == null) { Debuger.LogError("don't support response messageId:" + responseMessage.MessageId); return(null); } byte[] headerBytes = new byte[buffer.ReadInt()]; buffer.ReadBytes(headerBytes, 0, headerBytes.Length); byte[] messageBytes = new byte[buffer.ReadInt()]; buffer.ReadBytes(messageBytes, 0, messageBytes.Length); byte[] eventListBytes = new byte[buffer.ReadInt()]; buffer.ReadBytes(eventListBytes, 0, eventListBytes.Length); responseMessage.Header = new Header(); ThriftSerialize.DeSerialize(responseMessage.Header, headerBytes); responseMessage.Message = message; ThriftSerialize.DeSerialize(message, messageBytes); responseMessage.EventList = new MEventList(); ThriftSerialize.DeSerialize(responseMessage.EventList, eventListBytes); return(responseMessage); }
private byte[] Encode(Header header, TBase message) { byte[] headerBytes = ThriftSerialize.Serialize(header); byte[] messageBytes = ThriftSerialize.Serialize(message); ByteBuffer buffer = ByteBuffer.Allocate(512); buffer.WriteInt(ThriftMessageHelper.GetMessageId(message)); buffer.WriteInt(headerBytes.Length); buffer.WriteBytes(headerBytes); buffer.WriteInt(messageBytes.Length); buffer.WriteBytes(messageBytes); return(buffer.ToArray()); }