Пример #1
0
        public void TestEmptyByteArray()
        {
            ByteArraySegmentMessage message = new ByteArraySegmentMessage
            {
                array = new ArraySegment <byte>(new byte[0])
            };

            byte[] data = MessagePacker.PackWithAlloc(message);

            ByteArraySegmentMessage unpacked = MessagePacker.Unpack <ByteArraySegmentMessage>(data);

            Assert.IsNotNull(unpacked.array.Array);
            Assert.That(unpacked.array.Count, Is.EqualTo(0));
        }
Пример #2
0
        public void TestNullByteArray()
        {
            ByteArraySegmentMessage message = new ByteArraySegmentMessage
            {
                array = default
            };

            byte[] data = MessagePacker.PackWithAlloc(message);

            ByteArraySegmentMessage unpacked = MessagePacker.Unpack <ByteArraySegmentMessage>(data);

            Assert.IsNull(unpacked.array.Array);
            Assert.That(unpacked.array.Offset, Is.EqualTo(0));
            Assert.That(unpacked.array.Count, Is.EqualTo(0));
        }
Пример #3
0
        public void TestSegmentByteArray()
        {
            byte[] sourcedata = { 0, 1, 2, 3, 4, 5, 6 };

            ByteArraySegmentMessage message = new ByteArraySegmentMessage
            {
                array = new ArraySegment <byte>(sourcedata, 3, 2)
            };

            byte[] data = MessagePacker.PackWithAlloc(message);

            ByteArraySegmentMessage unpacked = MessagePacker.Unpack <ByteArraySegmentMessage>(data);

            Assert.IsNotNull(unpacked.array.Array);
            Assert.That(unpacked.array.Count, Is.EqualTo(2));
            Assert.That(unpacked.array, Is.EquivalentTo(new byte[] { 3, 4 }));
        }