public MemoryStreamData Encode(CommandPacket commandPacket)
        {
            MemoryStreamData memoryStreamDataInstance = ClientProtocolInstancesCache.GetMemoryStreamDataInstance();
            ProtocolBuffer   protocolBufferInstance   = ClientProtocolInstancesCache.GetProtocolBufferInstance();
            List <Command>   commands = commandPacket.Commands;
            int count = commands.Count;

            for (int i = 0; i < count; i++)
            {
                this.commandsCodec.Encode(protocolBufferInstance, commands[i]);
            }
            this.protocol.WrapPacket(protocolBufferInstance, memoryStreamDataInstance);
            ClientProtocolInstancesCache.ReleaseProtocolBufferInstance(protocolBufferInstance);
            return(memoryStreamDataInstance);
        }
 private void KeepPartialReceivedData()
 {
     if (this.IsPartialDataEmpty())
     {
         this.partialReceivedData.Position = 0L;
         this.partialReceivedData.SetLength(0L);
     }
     else
     {
         long             position            = this.partialReceivedData.Position;
         long             length              = this.partialReceivedData.Length;
         MemoryStreamData partialReceivedData = this.partialReceivedData;
         this.partialReceivedData = ClientProtocolInstancesCache.GetMemoryStreamDataInstance();
         this.partialReceivedData.Write(partialReceivedData.GetBuffer(), (int)position, (int)(length - position));
         ClientProtocolInstancesCache.ReleaseMemoryStreamData(partialReceivedData);
     }
 }
 public ProtocolAdapterImpl(Protocol protocol, CommandsCodec commandsCodec)
 {
     this.protocol            = protocol;
     this.commandsCodec       = commandsCodec;
     this.partialReceivedData = ClientProtocolInstancesCache.GetMemoryStreamDataInstance();
 }