示例#1
0
        /// <inheritdoc cref="IMessageReader.ReadFrom"/>
        public IMessage ReadFrom(ref SpanBufferReader bufferReader, byte packetProperty)
        {
            if (packetProperty != 0x00)
            {
                var readPacketProperty = bufferReader.ReadUInt8();
                if (readPacketProperty != packetProperty)
                {
                    throw new InvalidDataContractException(
                              "Invalid packet property " +
                              $"(PacketProperty={readPacketProperty}, Expected={packetProperty})."
                              );
                }
            }
            var messageGroup = bufferReader.ReadUInt32();

            if (!_messageRegistries.TryGetValue(messageGroup, out var messageRegistry))
            {
                throw new InvalidDataContractException($"Invalid message group (MessageGroup={messageGroup}).");
            }
            var protocolVersion = bufferReader.ReadVarUInt();

            if (protocolVersion != ProtocolVersion)
            {
                throw new InvalidDataContractException($"Invalid message protocol version (ProtocolVersion={protocolVersion}).");
            }
            var length = bufferReader.ReadVarUInt();

            if (bufferReader.RemainingSize < length)
            {
                throw new InvalidDataContractException($"Message truncated (RemainingSize={bufferReader.RemainingSize}, Expected={length}).");
            }
            var messageId = bufferReader.ReadVarUInt();

            if (!messageRegistry.TryCreateMessage(messageId, out var message))
            {
                throw new InvalidDataContractException($"Invalid message identifier (MessageId={messageId}).");
            }
            if (message is IReliableRequest)
            {
                ((IReliableRequest)message).RequestId = bufferReader.ReadUInt32();
            }
            if (message is IReliableResponse)
            {
                ((IReliableResponse)message).ResponseId = bufferReader.ReadUInt32();
            }
            message.ReadFrom(ref bufferReader);
            return(message);
        }
示例#2
0
 public override void ReadFrom(ref SpanBufferReader bufferReader)
 {
     MultipartMessageId = bufferReader.ReadUInt32();
     Offset             = bufferReader.ReadVarUInt();
     Length             = bufferReader.ReadVarUInt();
     TotalLength        = bufferReader.ReadVarUInt();
     if (Length > _maximumLength)
     {
         throw new InvalidDataContractException($"Length must not surpass {_maximumLength} bytes");
     }
     if (TotalLength > _maximumTotalLength)
     {
         throw new InvalidDataContractException($"Length must not surpass {_maximumTotalLength} bytes");
     }
     Data = bufferReader.ReadBytes((int)Length).ToArray();
 }
示例#3
0
 public override void ReadFrom(ref SpanBufferReader bufferReader)
 {
     UserId             = bufferReader.ReadString();
     UserName           = bufferReader.ReadString();
     Secret             = bufferReader.ReadString();
     CurrentPlayerCount = bufferReader.ReadVarUInt();
 }
        public override void ReadFrom(ref SpanBufferReader bufferReader)
        {
            Certificates = new List <byte[]>();
            var certificateCount = bufferReader.ReadVarUInt();

            for (var i = 0; i < certificateCount; i++)
            {
                Certificates.Add(bufferReader.ReadVarBytes().ToArray());
            }
        }