Exemplo n.º 1
0
        public void TestReadWriteRerror()
        {
            var stream  = new MemoryStream();
            var message = new Rerror("ETEST")
            {
                Tag = 1238
            };

            var p = new Protocol.Protocol(stream);

            p.Write(message);
            stream.Position = 0;

            var data   = new byte[message.Length];
            var length = stream.Read(data, 0, (int)message.Length);

            Assert.That(length, Is.EqualTo(message.Length));

            stream.Position = 0;
            var message2 = (Rerror)p.Read();

            Assert.That(message, Is.EqualTo(message2));
        }
Exemplo n.º 2
0
        public Message Read()
        {
            Message message;
            var     bytes  = ReadMessage();
            var     offset = Constants.Bit32Sz;
            var     type   = bytes[offset];

            switch (type)
            {
            case (byte)MessageType.Tversion:
                message = new Tversion(bytes);
                break;

            case (byte)MessageType.Rversion:
                message = new Rversion(bytes);
                break;

            case (byte)MessageType.Tauth:
                message = new Tauth(bytes);
                break;

            case (byte)MessageType.Rauth:
                message = new Rauth(bytes);
                break;

            case (byte)MessageType.Tattach:
                message = new Tattach(bytes);
                break;

            case (byte)MessageType.Rattach:
                message = new Rattach(bytes);
                break;

            case (byte)MessageType.Rerror:
                message = new Rerror(bytes);
                break;

            case (byte)MessageType.Tflush:
                message = new Tflush(bytes);
                break;

            case (byte)MessageType.Rflush:
                message = new Rflush(bytes);
                break;

            case (byte)MessageType.Twalk:
                message = new Twalk(bytes);
                break;

            case (byte)MessageType.Rwalk:
                message = new Rwalk(bytes);
                break;

            case (byte)MessageType.Topen:
                message = new Topen(bytes);
                break;

            case (byte)MessageType.Ropen:
                message = new Ropen(bytes);
                break;

            case (byte)MessageType.Tcreate:
                message = new Tcreate(bytes);
                break;

            case (byte)MessageType.Rcreate:
                message = new Rcreate(bytes);
                break;

            case (byte)MessageType.Tread:
                message = new Tread(bytes);
                break;

            case (byte)MessageType.Rread:
                message = new Rread(bytes);
                break;

            case (byte)MessageType.Twrite:
                message = new Twrite(bytes);
                break;

            case (byte)MessageType.Rwrite:
                message = new Rwrite(bytes);
                break;

            case (byte)MessageType.Tclunk:
                message = new Tclunk(bytes);
                break;

            case (byte)MessageType.Rclunk:
                message = new Rclunk(bytes);
                break;

            case (byte)MessageType.Tremove:
                message = new Tremove(bytes);
                break;

            case (byte)MessageType.Rremove:
                message = new Rremove(bytes);
                break;

            case (byte)MessageType.Tstat:
                message = new Tstat(bytes);
                break;

            case (byte)MessageType.Rstat:
                message = new Rstat(bytes);
                break;

            case (byte)MessageType.Twstat:
                message = new Twstat(bytes);
                break;

            case (byte)MessageType.Rwstat:
                message = new Rwstat(bytes);
                break;

            default:
                throw new Exception("Unsupported Message Type");
            }
            return(message);
        }