Ejemplo n.º 1
0
        public void TestMpackDataPlusDataWriteRead()
        {
            // Arrange
            DataMessage args1 = new DataMessage();

            args1.Source  = new NullSocketAddress();
            args1.Payload = new byte[145];
            args1.Control = new byte[0];
            new Random().NextBytes(args1.Payload);
            DataMessage args2 = new DataMessage();

            args2.Source  = new NullSocketAddress();
            args2.Payload = new byte[600];
            args2.Control = new byte[0];
            new Random().NextBytes(args2.Payload);
            DataMessage args3 = new DataMessage();

            args3.Source  = new NullSocketAddress();
            args3.Payload = new byte[400];
            args3.Control = new byte[30];
            new Random().NextBytes(args3.Payload);
            new Random().NextBytes(args3.Control);

            Message      datagramIn1 = new Message(null, null, null, args1);
            Message      datagramIn2 = new Message(null, null, null, args2);
            Message      datagramIn3 = new Message(null, null, null, args3);
            MemoryStream stream      = new MemoryStream();

            // Act
            datagramIn1.Encode(stream, CodecId.Mpack);
            datagramIn2.Encode(stream, CodecId.Mpack);
            datagramIn3.Encode(stream, CodecId.Mpack);
            byte[] buf = Interop.MessageDecodeEncode(CodecId.Mpack, 3, stream.GetBuffer(), stream.Length, buffer, buffer.Length);

            stream = new MemoryStream(buf);
            Message returned1 = Message.Decode(stream, CodecId.Mpack);
            Message returned2 = Message.Decode(stream, CodecId.Mpack);
            Message returned3 = Message.Decode(stream, CodecId.Mpack);

            // Assert
            Assert.IsTrue(datagramIn1.Equals(returned1));
            Assert.IsTrue(datagramIn2.Equals(returned2));
            Assert.IsTrue(datagramIn3.Equals(returned3));
        }
Ejemplo n.º 2
0
        public void TestMpackDataWriteRead2()
        {
            // Arrange
            var args = DataMessage.Create(new byte[600], new AnySocketAddress(), new byte[50], 12);

            new Random().NextBytes(args.Payload);
            new Random().NextBytes(args.Control);

            var datagramIn = Message.Create(null, null, null, args);
            var stream     = new MemoryStream();

            // Act
            datagramIn.Encode(stream, CodecId.Mpack);
            byte[] buf      = Interop.MessageDecodeEncode(CodecId.Mpack, 1, stream.GetBuffer(), stream.Length, buffer, buffer.Length);
            var    returned = Serializable.Decode <Message>(new MemoryStream(buf), CodecId.Mpack);

            // Assert
            Assert.IsTrue(datagramIn.Equals(returned));
        }
Ejemplo n.º 3
0
        public void TestJsonDataWriteRead1()
        {
            // Arrange
            var source = new Inet4SocketAddress(0xffaabbcc, 9643);
            var args   = DataMessage.Create(new byte[145], source, 12);

            new Random().NextBytes(args.Payload);

            var datagramIn = Message.Create(null, null, null, args);
            var stream     = new MemoryStream();

            // Act
            datagramIn.Encode(stream, CodecId.Json);
            byte[] buf      = Interop.MessageDecodeEncode(CodecId.Json, 1, stream.GetBuffer(), stream.Length, buffer, buffer.Length);
            var    returned = Serializable.Decode <Message>(new MemoryStream(buf), CodecId.Json);

            // Assert
            Assert.IsTrue(datagramIn.Equals(returned));
        }
Ejemplo n.º 4
0
        public void TestJsonDataWriteRead2()
        {
            // Arrange
            DataMessage args = new DataMessage();

            args.Source  = new NullSocketAddress();
            args.Payload = new byte[600];
            new Random().NextBytes(args.Payload);

            Message      datagramIn = new Message(null, null, null, args);
            MemoryStream stream     = new MemoryStream();

            // Act
            datagramIn.Encode(stream, CodecId.Json);
            byte[]  buf      = Interop.MessageDecodeEncode(CodecId.Json, 1, stream.GetBuffer(), stream.Length, buffer, buffer.Length);
            Message returned = Message.Decode(new MemoryStream(buf), CodecId.Json);

            // Assert
            Assert.IsTrue(datagramIn.Equals(returned));
        }
Ejemplo n.º 5
0
        public void TestMpackDataWriteRead1()
        {
            // Arrange
            Inet4SocketAddress source = new Inet4SocketAddress(0xffaabbcc, 9643, 1);

            DataMessage args = new DataMessage();

            args.Source  = source;
            args.Payload = new byte[145];
            new Random().NextBytes(args.Payload);

            Message      datagramIn = new Message(null, null, null, args);
            MemoryStream stream     = new MemoryStream();

            // Act
            datagramIn.Encode(stream, CodecId.Mpack);
            byte[]  buf      = Interop.MessageDecodeEncode(CodecId.Mpack, 1, stream.GetBuffer(), stream.Length, buffer, buffer.Length);
            Message returned = Message.Decode(new MemoryStream(buf), CodecId.Mpack);

            // Assert
            Assert.IsTrue(datagramIn.Equals(returned));
        }