Exemplo n.º 1
0
        public void TestMpackDataPlusDataWriteRead()
        {
            // Arrange
            var args1 = DataMessage.Create(new byte[145], new AnySocketAddress(), 11);

            new Random().NextBytes(args1.Payload);
            var args2 = DataMessage.Create(new byte[600], new AnySocketAddress(), 12);

            new Random().NextBytes(args2.Payload);
            var args3 = DataMessage.Create(new byte[400], new AnySocketAddress(), new byte[30], 13);

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

            var datagramIn1 = Message.Create(null, null, null, args1);
            var datagramIn2 = Message.Create(null, null, null, args2);
            var datagramIn3 = Message.Create(null, null, null, args3);
            var 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 = Serializable.Decode <Message>(stream, CodecId.Mpack);
            Message returned2 = Serializable.Decode <Message>(stream, CodecId.Mpack);
            Message returned3 = Serializable.Decode <Message>(stream, CodecId.Mpack);

            // Assert
            Assert.IsTrue(datagramIn1.Equals(returned1));
            Assert.IsTrue(datagramIn2.Equals(returned2));
            Assert.IsTrue(datagramIn3.Equals(returned3));
        }
Exemplo n.º 2
0
        public void TestMpackOpenPlusDataWriteRead()
        {
            // Arrange
            var args1 = OpenRequest.Create(new Reference(), (int)CodecId.Mpack,
                                           "dfksjaödfjkasdfölskajdfölsadfjkslöajksadlöjksdlöfsjkadflösdajkfösdlafj", 0, false);
            var args2 = DataMessage.Create(new byte[600], new AnySocketAddress(), 12);

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

            var datagramIn1 = Message.Create(null, null, null, args1);
            var datagramIn2 = Message.Create(null, null, null, args2);
            var stream      = new MemoryStream();

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

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

            // Assert
            Assert.IsTrue(datagramIn1.Equals(returned1));
            Assert.IsTrue(datagramIn2.Equals(returned2));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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));
        }