public static List<object> Deserialize(ActorSystem system, ByteString message)
        {
            var result = new List<object>();

            while (!message.IsEmpty)
            {
                var seriliazerId = BitConverter.ToInt32(message.Take(SeriliazerIdBytesCount).ToArray(), 0);
                var messageLength = BitConverter.ToInt32(message.Skip(SeriliazerIdBytesCount).Take(MessageLengthBytesCount).ToArray(), 0);
                var messageBytes = message.Skip(CompletePrefixBytesCount).Take(messageLength).ToArray();
                var seriliazer = system.Serialization.GetSerializerById(seriliazerId);

                result.Add(seriliazer.FromBinary(messageBytes, typeof(object)));

                message = message.Drop(CompletePrefixBytesCount + messageLength);
            }

            return result;
        }
Exemple #2
0
 private static int Compare(ByteString b1, ByteString b2)
 {
     if (b1.IsEmpty)
         return b2.IsEmpty ? 0 : 2;
     return b2.IsEmpty ? 1 : 3;
 }
Exemple #3
0
            /// <summary></summary>
            /// <exception cref="InvalidOperationException">
            /// This exception is thrown if this <see cref="ByteString"/> cannot be concatenated with <paramref name="that"/>.
            /// </exception>
            public override ByteString Concat(ByteString that)
            {
                if (that.IsEmpty)
                {
                    return this;
                }
                else if (this.IsEmpty)
                {
                    return that;
                }
                else
                {
                    var b1c = that as ByteString1C;
                    if (b1c != null)
                    {
                        return new ByteStrings(Items.Concat(b1c.ToByteString1()).ToArray());
                    }

                    var b1 = that as ByteString1;
                    if (b1 != null)
                    {
                        return new ByteStrings(Items.Concat(b1).ToArray());
                    }

                    var bs = that as ByteStrings;
                    if (bs != null)
                    {
                        return new ByteStrings(Items.Concat(bs.Items).ToArray());
                    }

                    throw new InvalidOperationException($"No suitable implementation found for concatenating ByteString of type {that.GetType()}");
                }
            }
Exemple #4
0
            /// <summary></summary>
            /// <exception cref="InvalidOperationException"></exception>
            public override ByteString Concat(ByteString that)
            {
                if (that.IsEmpty) return this;
                if (this.IsEmpty) return that;

                var b1C = that as ByteString1C;
                if (b1C != null)
                    return new ByteStrings(this, b1C.ToByteString1());

                var b1 = that as ByteString1;
                if (b1 != null)
                {
                    if (_bytes == b1._bytes && (_startIndex + _length == b1._startIndex))
                        return new ByteString1(_bytes, _startIndex, _length + b1._length);
                    return new ByteStrings(this, b1);
                }

                var bs = that as ByteStrings;
                if (bs != null)
                {
                    return Create(this, bs);
                }

                throw new InvalidOperationException();
            }
Exemple #5
0
 public override ByteString Concat(ByteString that)
 {
     if (that.IsEmpty) return this;
     if (this.IsEmpty) return that;
     return ToByteString1() + that;
 }
Exemple #6
0
 private void ValidateServerClientCommunication(ByteString testData, ServerConnection serverConnection, TcpReadProbe readProbe, TcpWriteProbe writeProbe)
 {
     serverConnection.Write(testData);
     serverConnection.Read(5);
     readProbe.Read(5).ShouldBeEquivalentTo(testData);
     writeProbe.Write(testData);
     serverConnection.WaitRead().ShouldBeEquivalentTo(testData);
 }
Exemple #7
0
 public ReadResult(ByteString bytes)
 {
     Bytes = bytes;
 }
Exemple #8
0
            public void Write(ByteString bytes)
            {
                if (_demand == 0)
                    _demand += TcpWriteSubscription.Value.ExpectRequest();

                TcpWriteSubscription.Value.SendNext(bytes);
                _demand -= 1;
            }
Exemple #9
0
 public ClientWrite(ByteString bytes)
 {
     Bytes = bytes;
 }
Exemple #10
0
 public void Write(ByteString bytes) => _connectionActor.Tell(new ClientWrite(bytes));
Exemple #11
0
 protected override void OnReceive(object message)
 {
     message.Match().With<ClientWrite>(w =>
     {
         if (!_writePending)
         {
             _writePending = true;
             _connection.Tell(Tcp.Write.Create(w.Bytes, WriteAck.Instance));
         }
         else
             _queuedWrites.Enqueue(w.Bytes);
     }).With<WriteAck>(() =>
     {
         if (_queuedWrites.Count != 0)
         {
             var next = _queuedWrites.Dequeue();
             _connection.Tell(Tcp.Write.Create(next, WriteAck.Instance));
         }
         else
         {
             _writePending = false;
             if(_closeAfterWrite != null)
                 _connection.Tell(_closeAfterWrite);
         }
     }).With<ClientRead>(r =>
     {
         _readTo = r.ReadTo;
         _toRead = r.Count;
         _connection.Tell(Tcp.ResumeReading.Instance);
     }).With<Tcp.Received>(r =>
     {
         _readBuffer += r.Data;
         if (_readBuffer.Count >= _toRead)
         {
             _readTo.Tell(new ReadResult(_readBuffer));
             _readBuffer = ByteString.Empty;
             _toRead = 0;
             _readTo = Context.System.DeadLetters;
         }
         else
             _connection.Tell(Tcp.ResumeReading.Instance);
     }).With<PingClose>(p =>
     {
         _readTo = p.Requester;
         _connection.Tell(Tcp.ResumeReading.Instance);
     }).With<Tcp.ConnectionClosed>(c =>
     {
         _readTo.Tell(c);
         if(!c.IsPeerClosed)
             Context.Stop(Self);
     }).With<ClientClose>(c =>
     {
         if (!_writePending)
             _connection.Tell(c.Cmd);
         else
             _closeAfterWrite = c.Cmd;
     });
 }
Exemple #12
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="data">TBD</param>
 public Received(ByteString data)
 {
     Data = data;
 }
Exemple #13
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="data">TBD</param>
 /// <returns>TBD</returns>
 public static Send Create(ByteString data)
 {
     return(new Send(data, NoAck.Instance));
 }
Exemple #14
0
 private PendingWrite CreatePendingBufferWrite(IActorRef commander, ByteString data, Tcp.Event ack, WriteCommand tail)
 {
     return(new PendingBufferWrite(this, SendArgs, Self, commander, data, ack, tail));
 }