Beispiel #1
0
        public static ProtocolHeader ReadHeader(BinaryReader reader)
        {
            ProtocolHeader header = new ProtocolHeader();

            header.Read(reader);

            return(header);
        }
Beispiel #2
0
        public static ProtocolPacket ReadRequest(BinaryReader reader, ProtocolHeader header)
        {
            ProtocolPacket packet = null;

            switch (header.OpCode)
            {
            case CommandOpCode.Get:
            case CommandOpCode.GetK:
            case CommandOpCode.GetKQ:
                if (header.Magic == ProtocolPacket.RequestMagic)
                {
                    packet = new GetRequest(header);
                }
                else if (header.Magic == ProtocolPacket.ResponseMagic)
                {
                    packet = new GetResponse(header);
                }
                break;

            case CommandOpCode.Set:
            case CommandOpCode.SetQ:
                if (header.Magic == ProtocolPacket.RequestMagic)
                {
                    packet = new SetRequest(header);
                }
                else if (header.Magic == ProtocolPacket.ResponseMagic)
                {
                    packet = new SetResponse(header);
                }
                break;
            }

            if (packet != null)
            {
                packet.Read(reader);

                if (!packet.Validate())
                {
                    throw new ProtocolException()
                          {
                              Status = ResponseStatus.InvalidArguments
                          };
                }
            }
            else
            {
                throw new ProtocolException()
                      {
                          Status = ResponseStatus.UnknownCommand
                      };
            }

            return(packet);
        }
Beispiel #3
0
 public GetRequest(ProtocolHeader header)
     : base(header)
 {
     this.Header.Magic = ProtocolPacket.RequestMagic;
 }
Beispiel #4
0
 public GetResponse(ProtocolHeader header)
     : base(header)
 {
     this.Header.Magic = ProtocolPacket.ResponseMagic;
 }
Beispiel #5
0
 public static ProtocolPacket ReadRequest(BinaryReader reader)
 {
     return(ProtocolPacket.ReadRequest(reader, ProtocolHeader.ReadHeader(reader)));
 }
Beispiel #6
0
 public ProtocolPacket(ProtocolHeader header)
 {
     this.Header = header;
 }