Beispiel #1
0
        public byte[] Serialize(AddonMessage message)
        {
            byte[] output;

            this.SerializeValue(message.Count);
            this.SerializeValue(message.Type);

            foreach (var value in message)
            {
                this.SerializeValue(value);
            }

            output  = _buffer.ToArray();
            _buffer = new MemoryStream();

            return(output);
        }
Beispiel #2
0
        public BinaryDeserializer()
        {
            _buffer     = new MemoryStream();
            _message    = null;
            _length     = -1;
            _partLength = 0;

            OnDeserializedValue += (value) =>
            {
                if (_length == -1)
                {
                    _length = Convert.ToInt32(value);
                }
                else
                {
                    if (_message == null)
                    {
                        _message = new AddonMessage((string)value);
                    }
                    else
                    {
                        _message.Add(value);
                    }

                    if (_length == _message.Count)
                    {
                        OnDeserializedMessage?.Invoke(_message);

                        _message = null;
                        _length  = -1;
                    }
                }

                State = EnumState.INIT;
            };
        }
Beispiel #3
0
 public void Send(AddonMessage message) =>
 this.Socket.Send(this.Serializer.Serialize(message));