示例#1
0
        public void WriteEntryUpdate3()
        {
            uint        id  = 1;
            uint        seq = 1;
            Value       val = Value.MakeDouble(5);
            Message     msg = Message.EntryUpdate(id, seq, val);
            WireEncoder enc = new WireEncoder(0x0300);

            msg.Write(enc);
            byte[]      buf  = enc.Buffer;
            WireDecoder dec  = new WireDecoder(new MemoryStream(buf), 0x0300);
            byte        u8   = 0;
            NtType      type = 0;
            ushort      u16  = 0;

            Assert.That(dec.Read8(ref u8), Is.True);
            Assert.That(u8, Is.EqualTo((byte)EntryUpdate));
            Assert.That(dec.Read16(ref u16), Is.True);
            Assert.That(u16, Is.EqualTo(id));
            Assert.That(dec.Read16(ref u16), Is.True);
            Assert.That(u16, Is.EqualTo(seq));
            Assert.That(dec.ReadType(ref type), Is.True);
            Assert.That(type, Is.EqualTo(NtType.Double));
            val = dec.ReadValue(type);
            Assert.That(val, Is.Not.Null);
            Assert.That(val.Type, Is.EqualTo(NtType.Double));
            Assert.That(val.GetDouble(), Is.EqualTo(5));
        }
        public void WireEncoderWriteDouble()
        {
            int         off = BUFSIZE - 8;
            WireEncoder e   = new WireEncoder(0x0300);

            for (int i = 0; i < off; i++)
            {
                e.Write8(0);
            }
            e.WriteDouble(0.0);
            e.WriteDouble(2.3e5);
            e.WriteDouble(double.PositiveInfinity);
            e.WriteDouble(2.2250738585072014e-308);//Minimum double size
            e.WriteDouble(double.MaxValue);

            Assert.That(e.Buffer.Length - off, Is.EqualTo(40));
            byte[] checkArray =
            {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x41, 0x0c, 0x13, 0x80, 0x00, 0x00, 0x00, 0x00,
                0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x7f, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
            };
            byte[] bufferArray = new byte[checkArray.Length];
            Array.Copy(e.Buffer, off, bufferArray, 0, checkArray.Length);
            Assert.That(bufferArray, Is.EquivalentTo(checkArray));
        }
示例#3
0
        public void WriteEntryAssign2()
        {
            uint        id    = 1;
            uint        seq   = 1;
            EntryFlags  flags = EntryFlags.Persistent;
            string      name  = "Testing";
            Value       val   = Value.MakeDouble(5);
            Message     msg   = Message.EntryAssign(name, id, seq, val, flags);
            WireEncoder enc   = new WireEncoder(0x0200);

            msg.Write(enc);
            byte[]      buf  = enc.Buffer;
            WireDecoder dec  = new WireDecoder(new MemoryStream(buf), 0x0200);
            byte        u8   = 0;
            NtType      type = 0;
            string      str  = "";
            ushort      u16  = 0;

            Assert.That(dec.Read8(ref u8), Is.True);
            Assert.That(u8, Is.EqualTo((byte)EntryAssign));
            Assert.That(dec.ReadString(ref str), Is.True);
            Assert.That(str, Is.EqualTo(name));
            Assert.That(dec.ReadType(ref type), Is.True);
            Assert.That(type, Is.EqualTo(NtType.Double));
            Assert.That(dec.Read16(ref u16), Is.True);
            Assert.That(u16, Is.EqualTo(id));
            Assert.That(dec.Read16(ref u16), Is.True);
            Assert.That(u16, Is.EqualTo(seq));
            val = dec.ReadValue(type);
            Assert.That(val, Is.Not.Null);
            Assert.That(val.Type, Is.EqualTo(NtType.Double));
            Assert.That(val.GetDouble(), Is.EqualTo(5));
        }
        public void Construct()
        {
            WireEncoder d = new WireEncoder(0x0300);

            Assert.That(d.Error, Is.Null);
            Assert.That(d.ProtoRev, Is.EqualTo(0x0300));
        }
示例#5
0
        public void WriteRpcResponse3()
        {
            uint id  = 1;
            uint uid = 1;

            byte[]      rpc = new byte[] { 0, 1, 2, 3, 4 };
            Message     msg = Message.RpcResponse(id, uid, rpc);
            WireEncoder enc = new WireEncoder(0x0300);

            msg.Write(enc);
            byte[]      buf = enc.Buffer;
            WireDecoder dec = new WireDecoder(new MemoryStream(buf), 0x0300);
            byte        u8  = 0;
            ushort      u16 = 0;

            Assert.That(dec.Read8(ref u8), Is.True);
            Assert.That(u8, Is.EqualTo((byte)RpcResponse));
            Assert.That(dec.Read16(ref u16), Is.True);
            Assert.That(u16, Is.EqualTo(id));
            Assert.That(dec.Read16(ref u16), Is.True);
            Assert.That(u16, Is.EqualTo(uid));
            //Force Rpc as ExecuteRpc is Rpc
            Value val = dec.ReadValue(NtType.Rpc);

            Assert.That(val, Is.Not.Null);
            Assert.That(val.Type, Is.EqualTo(NtType.Rpc));
            Assert.That(val.GetRpc(), Is.EquivalentTo(rpc));
        }
示例#6
0
        public void TestWriteTypeError()
        {
            WireEncoder e = new WireEncoder();

            e.WriteType(NtType.Unassigned);
            Assert.That(e.Error, Is.EqualTo("Unrecognized Type"));
        }
示例#7
0
        /// <summary>
        /// Pack an Rpc defintion in to a byte array
        /// </summary>
        /// <param name="def">The definition to pack</param>
        /// <returns>The packed data</returns>
        public static byte[] PackRpcDefinition(RpcDefinition def)
        {
            WireEncoder enc = new WireEncoder(0x0300);

            enc.Write8((byte)def.Version);
            enc.WriteString(def.Name);

            int paramsSize = def.Params.Count;

            if (paramsSize > 0xff)
            {
                paramsSize = 0xff;
            }
            enc.Write8((byte)paramsSize);
            for (int i = 0; i < paramsSize; i++)
            {
                enc.WriteType(def.Params[i].DefValue.Type);
                enc.WriteString(def.Params[i].Name);
                enc.WriteValue(def.Params[i].DefValue);
            }

            int resultsSize = def.Results.Count;

            if (resultsSize > 0xff)
            {
                resultsSize = 0xff;
            }
            enc.Write8((byte)resultsSize);
            for (int i = 0; i < resultsSize; i++)
            {
                enc.WriteType(def.Results[i].Type);
                enc.WriteString(def.Results[i].Name);
            }
            return(enc.Buffer);
        }
        public void WriteString3()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteString(s_normal);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(6));
            Assert.That(e.Buffer, Is.EquivalentTo(new byte[] { 0x05, (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o' }));

            e.Reset();
            e.WriteString(s_long);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(130));
            byte[] arr = new[] { e.Buffer[0], e.Buffer[1], e.Buffer[2], e.Buffer[3] };
            Assert.That(arr, Is.EquivalentTo(new byte[] { 0x80, 0x01, (byte)'*', (byte)'*' }));
            Assert.That(e.Buffer[128], Is.EqualTo((byte)'*'));
            Assert.That(e.Buffer[129], Is.EqualTo((byte)'x'));

            e.Reset();
            e.WriteString(s_big);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(65540));
            arr = new[] { e.Buffer[0], e.Buffer[1], e.Buffer[2], e.Buffer[3] };
            Assert.That(arr, Is.EquivalentTo(new byte[] { 0x81, 0x80, 0x04, (byte)'*' }));
            Assert.That(e.Buffer[65536], Is.EqualTo((byte)'*'));
            Assert.That(e.Buffer[65537], Is.EqualTo((byte)'x'));
            Assert.That(e.Buffer[65538], Is.EqualTo((byte)'x'));
            Assert.That(e.Buffer[65539], Is.EqualTo((byte)'x'));
        }
        public void SetProtoRev()
        {
            WireEncoder d = new WireEncoder(0x0300);

            d.ProtoRev = 0x0200;
            Assert.That(d.ProtoRev, Is.EqualTo(0x0200));
        }
示例#10
0
        public void WriteEntryUpdate2()
        {
            uint        id  = 1;
            uint        seq = 1;
            Value       val = Value.MakeDouble(5);
            Message     msg = Message.EntryUpdate(id, seq, val);
            WireEncoder enc = new WireEncoder(0x0200);

            msg.Write(enc);
            byte[]      buf = enc.Buffer;
            WireDecoder dec = new WireDecoder(new MemoryStream(buf), 0x0200);
            byte        u8  = 0;
            ushort      u16 = 0;

            Assert.That(dec.Read8(ref u8), Is.True);
            Assert.That(u8, Is.EqualTo((byte)EntryUpdate));
            Assert.That(dec.Read16(ref u16), Is.True);
            Assert.That(u16, Is.EqualTo(id));
            Assert.That(dec.Read16(ref u16), Is.True);
            Assert.That(u16, Is.EqualTo(seq));
            //Forcing double, as rev 2 has a seperate function to grab
            val = dec.ReadValue(NtType.Double);
            Assert.That(val, Is.Not.Null);
            Assert.That(val.Type, Is.EqualTo(NtType.Double));
            Assert.That(val.GetDouble(), Is.EqualTo(5));
        }
示例#11
0
        public void TestWriteValueError()
        {
            WireEncoder e = new WireEncoder();

            e.WriteValue(v_empty);
            Assert.That(e.Buffer.Length, Is.EqualTo(0));
            Assert.That(e.Error, Is.Not.Null);
        }
示例#12
0
        public void GetStringSize3()
        {
            WireEncoder e = new WireEncoder(0x0300);

            Assert.That(e.GetStringSize(s_normal), Is.EqualTo(6));
            Assert.That(e.GetStringSize(s_long), Is.EqualTo(130));
            Assert.That(e.GetStringSize(s_big), Is.EqualTo(65540));
        }
示例#13
0
        public void WriteValueNull3()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteValue(null);
            Assert.That(e.Buffer.Length, Is.EqualTo(0));
            Assert.That(e.Error, Is.Not.Null);
        }
示例#14
0
        public void WriteRpcArray3()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteValue(v_rpc);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(6));
            Assert.That(e.Buffer, Is.EquivalentTo(new byte[] { 0x05, (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o' }));
        }
示例#15
0
        public void TestWriteRawArray()
        {
            WireEncoder e = new WireEncoder();

            e.WriteValue(v_raw);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(6));
            Assert.That(e.Buffer, Is.EquivalentTo(new byte[] { 0x05, (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o' }));
        }
示例#16
0
        public void WriteDoubleValue3()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteValue(v_double);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(8));
            Assert.That(e.Buffer, Is.EquivalentTo(new byte[] { 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }));
        }
示例#17
0
        public void WriteStringValue2()
        {
            WireEncoder e = new WireEncoder(0x0200);

            e.WriteValue(v_string);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(7));
            Assert.That(e.Buffer, Is.EquivalentTo(new byte[] { 0x00, 0x05, (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o' }));
        }
示例#18
0
        /// <summary>
        /// Pack a list of values
        /// </summary>
        /// <param name="values">The values to pack</param>
        /// <returns>The packed values</returns>
        public static byte[] PackRpcValues(IList <Value> values)
        {
            WireEncoder enc = new WireEncoder(0x0300);

            foreach (var value in values)
            {
                enc.WriteValue(value);
            }
            return(enc.Buffer);
        }
示例#19
0
        public void WriteClientHelloDone2()
        {
            //Client Hello Done does not do anything on 2
            Message     msg = Message.ClientHelloDone();
            WireEncoder enc = new WireEncoder(0x0200);

            msg.Write(enc);
            byte[] buf = enc.Buffer;
            Assert.That(buf, Has.Length.EqualTo(0));
        }
示例#20
0
        public void WriteClearEntries2()
        {
            //Flags not supported in 2
            Message     msg = Message.ClearEntries();
            WireEncoder enc = new WireEncoder(0x0200);

            msg.Write(enc);
            byte[] buf = enc.Buffer;
            Assert.That(buf, Has.Length.EqualTo(0));
        }
        public static byte[] PackRpcValues(params RpcValue[] values)
        {
            WireEncoder enc = new WireEncoder();

            foreach (var value in values)
            {
                enc.WriteValue(value);
            }
            return(enc.Buffer);
        }
示例#22
0
        public void WriteKeepAlive2()
        {
            Message     msg = Message.KeepAlive();
            WireEncoder enc = new WireEncoder(0x0200);

            msg.Write(enc);

            byte[] buf = enc.Buffer;
            Assert.That(buf, Has.Length.EqualTo(1));
            Assert.That(buf[0], Is.EqualTo((byte)KeepAlive));
        }
示例#23
0
        public void WriteEntryDelete2()
        {
            //Flags not supported in 2
            uint        id  = 1;
            Message     msg = Message.EntryDelete(id);
            WireEncoder enc = new WireEncoder(0x0200);

            msg.Write(enc);
            byte[] buf = enc.Buffer;
            Assert.That(buf, Has.Length.EqualTo(0));
        }
示例#24
0
        public void WriteServerHelloDone2()
        {
            Message     msg = Message.ServerHelloDone();
            WireEncoder enc = new WireEncoder(0x0200);

            msg.Write(enc);

            byte[] buf = enc.Buffer;
            Assert.That(buf, Has.Length.EqualTo(1));
            Assert.That(buf[0], Is.EqualTo((byte)ServerHelloDone));
        }
示例#25
0
        public void WriteRpcResponse2()
        {
            //Flags not supported in 2
            uint        id  = 1;
            uint        seq = 1;
            Message     msg = Message.RpcResponse(id, seq, new byte[1]);
            WireEncoder enc = new WireEncoder(0x0200);

            msg.Write(enc);
            byte[] buf = enc.Buffer;
            Assert.That(buf, Has.Length.EqualTo(0));
        }
示例#26
0
        public void WriteServerHello2()
        {
            //Server Hello does not do anything on 2
            uint        flags = 1;
            string      name  = "Testing";
            Message     msg   = Message.ServerHello(flags, name);
            WireEncoder enc   = new WireEncoder(0x0200);

            msg.Write(enc);
            byte[] buf = enc.Buffer;
            Assert.That(buf, Has.Length.EqualTo(0));
        }
示例#27
0
        public void WriteBooleanValue3()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteValue(v_boolean);
            var v_false = Value.MakeBoolean(false);

            e.WriteValue(v_false);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(2));
            Assert.That(e.Buffer, Is.EquivalentTo(new byte[] { 0x01, 0x00 }));
        }
示例#28
0
        public void WriteFlagsUpdate2()
        {
            //Flags not supported in 2
            uint        id    = 1;
            EntryFlags  flags = EntryFlags.Persistent;
            Message     msg   = Message.FlagsUpdate(id, flags);
            WireEncoder enc   = new WireEncoder(0x0200);

            msg.Write(enc);
            byte[] buf = enc.Buffer;
            Assert.That(buf, Has.Length.EqualTo(0));
        }
示例#29
0
        public void WriteClientHelloDone3()
        {
            Message     msg = Message.ClientHelloDone();
            WireEncoder enc = new WireEncoder(0x0300);

            msg.Write(enc);
            byte[]      buf = enc.Buffer;
            WireDecoder dec = new WireDecoder(new MemoryStream(buf), 0x0300);
            byte        u8  = 0;

            Assert.That(dec.Read8(ref u8), Is.True);
            Assert.That(u8, Is.EqualTo((byte)ClientHelloDone));
        }
示例#30
0
        public void Reset()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteType(NtType.Unassigned);
            Assert.That(e.Error, Is.Not.Null);
            e.Reset();
            Assert.That(e.Error, Is.Null);

            e.Write8(0);
            Assert.That(e.Buffer.Length, Is.EqualTo(1));
            e.Reset();
            Assert.That(e.Buffer, Is.Empty);
        }