public virtual void OnData(ByteBuffer buffer)
 {
     while (buffer.HasRemaining())
     {
         var complete = _message.ReadFrom(buffer);
         if (!complete)
         {
             return;
         }
         //MESSAGE IS COMPLETE HERE
         if (_message.IsFlagSet(ClientMessage.BeginAndEndFlags))
         {
             //HANDLE-MESSAGE
             HandleMessage(_message);
             _message = ClientMessage.Create();
             continue;
         }
         if (_message.IsFlagSet(ClientMessage.BeginFlag))
         {
             // first fragment
             var builder = new BufferBuilder();
             _builderBySessionIdMap.Add(_message.GetCorrelationId(), builder);
             builder.Append(_message.GetBuffer(), 0, _message.GetFrameLength());
         }
         else
         {
             var builder = _builderBySessionIdMap[_message.GetCorrelationId()];
             if (builder.Position() == 0)
             {
                 throw new InvalidOperationException();
             }
             builder.Append(_message.GetBuffer(), _message.GetDataOffset(),
                 _message.GetFrameLength() - _message.GetDataOffset());
             if (_message.IsFlagSet(ClientMessage.EndFlag))
             {
                 var msgLength = builder.Position();
                 var cm = ClientMessage.CreateForDecode(builder.Buffer(), 0);
                 cm.SetFrameLength(msgLength);
                 //HANDLE-MESSAGE
                 HandleMessage(cm);
                 _builderBySessionIdMap.Remove(_message.GetCorrelationId());
             }
         }
         _message = ClientMessage.Create();
     }
 }
Esempio n. 2
0
 public virtual void OnData(ByteBuffer buffer)
 {
     while (buffer.HasRemaining())
     {
         var complete = _message.ReadFrom(buffer);
         if (!complete)
         {
             return;
         }
         //MESSAGE IS COMPLETE HERE
         if (_message.IsFlagSet(ClientMessage.BeginAndEndFlags))
         {
             //HANDLE-MESSAGE
             HandleMessage(_message);
             _message = ClientMessage.Create();
             continue;
         }
         if (_message.IsFlagSet(ClientMessage.BeginFlag))
         {
             // first fragment
             var builder = new BufferBuilder();
             _builderBySessionIdMap.Add(_message.GetCorrelationId(), builder);
             builder.Append(_message.GetBuffer(), 0, _message.GetFrameLength());
         }
         else
         {
             var builder = _builderBySessionIdMap[_message.GetCorrelationId()];
             if (builder.Position() == 0)
             {
                 throw new InvalidOperationException();
             }
             builder.Append(_message.GetBuffer(), _message.GetDataOffset(),
                            _message.GetFrameLength() - _message.GetDataOffset());
             if (_message.IsFlagSet(ClientMessage.EndFlag))
             {
                 var msgLength = builder.Position();
                 var cm        = ClientMessage.CreateForDecode(builder.ProtocolBuffer(), 0);
                 cm.SetFrameLength(msgLength);
                 //HANDLE-MESSAGE
                 HandleMessage(cm);
                 _builderBySessionIdMap.Remove(_message.GetCorrelationId());
             }
         }
         _message = ClientMessage.Create();
     }
 }