Пример #1
0
        public void TestNullArray()
        {
            MsgPackWriter writer = new MsgPackWriter(Allocator.Temp);

            writer.WriteNil();

            MsgPackReader reader = new MsgPackReader(writer.ToArray(Allocator.Temp));

            Assert.That(reader.ReadArrayHeader(out var len), Is.False);
        }
        public void NullString()
        {
            MsgPackWriter writer = new MsgPackWriter(Allocator.Temp);

            writer.WriteNil();

            MsgPackReader reader = new MsgPackReader(writer.ToArray(Allocator.Temp));

            Assert.That(reader.ReadString(), Is.Null);
        }
        public void StringFixedLen()
        {
            MsgPackWriter writer     = new MsgPackWriter(Allocator.Temp);
            var           testString = GetRandomizedAsciiCharactersString(4);

            writer.WriteString(testString);

            MsgPackReader reader = new MsgPackReader(writer.ToArray(Allocator.Temp));

            Assert.That(reader.ReadString(), Is.EqualTo(testString));
        }
        public void LargeUnicodeString()
        {
            MsgPackWriter writer     = new MsgPackWriter(Allocator.Temp);
            var           testString = GetRandomizedUnicodeCharactersString(ushort.MaxValue + 1);

            writer.WriteString(testString);

            MsgPackReader reader = new MsgPackReader(writer.ToArray(Allocator.Temp));

            Assert.That(reader.ReadString(), Is.EqualTo(testString));
        }
        public void Raw8()
        {
            MsgPackWriter writer = new MsgPackWriter(Allocator.Temp);

            writer.WriteRaw8(byte.MinValue);
            writer.WriteRaw8(byte.MaxValue);

            MsgPackReader reader = new MsgPackReader(writer.ToArray(Allocator.Temp));

            Assert.That(reader.ReadRaw8(), Is.EqualTo(byte.MinValue));
            Assert.That(reader.ReadRaw8(), Is.EqualTo(byte.MaxValue));
        }
        public void Raw64()
        {
            MsgPackWriter writer = new MsgPackWriter(Allocator.Temp);

            writer.WriteRawBigEndian64(ulong.MinValue);
            writer.WriteRawBigEndian64(ulong.MaxValue);

            MsgPackReader reader = new MsgPackReader(writer.ToArray(Allocator.Temp));

            Assert.That(reader.ReadRawBigEndian64(), Is.EqualTo(ulong.MinValue));
            Assert.That(reader.ReadRawBigEndian64(), Is.EqualTo(ulong.MaxValue));
        }
        public void SingleTest()
        {
            MsgPackWriter writer = new MsgPackWriter(Allocator.Temp);

            writer.WriteSingle(float.MinValue);
            writer.WriteSingle(float.MaxValue);
            writer.WriteSingle(float.Epsilon);

            MsgPackReader reader = new MsgPackReader(writer.ToArray(Allocator.Temp));

            Assert.That(reader.ReadSingle(), Is.EqualTo(float.MinValue));
            Assert.That(reader.ReadSingle(), Is.EqualTo(float.MaxValue));
            Assert.That(reader.ReadSingle(), Is.EqualTo(float.Epsilon));
        }
        public void UInt32Test()
        {
            MsgPackWriter writer = new MsgPackWriter(Allocator.Temp);

            writer.WriteInteger(uint.MinValue);
            writer.WriteInteger(uint.MaxValue);
            writer.WriteInteger((uint)0);

            MsgPackReader reader = new MsgPackReader(writer.ToArray(Allocator.Temp));

            Assert.That(reader.ReadUInt32(), Is.EqualTo(uint.MinValue));
            Assert.That(reader.ReadUInt32(), Is.EqualTo(uint.MaxValue));
            Assert.That(reader.ReadUInt32(), Is.EqualTo(0));
        }
        public void Int8Test()
        {
            MsgPackWriter writer = new MsgPackWriter(Allocator.Temp);

            writer.WriteInteger(sbyte.MinValue);
            writer.WriteInteger(sbyte.MaxValue);
            writer.WriteInteger((sbyte)0);

            MsgPackReader reader = new MsgPackReader(writer.ToArray(Allocator.Temp));

            Assert.That(reader.ReadInt8(), Is.EqualTo(sbyte.MinValue));
            Assert.That(reader.ReadInt8(), Is.EqualTo(sbyte.MaxValue));
            Assert.That(reader.ReadInt8(), Is.EqualTo(0));
        }
Пример #10
0
        public void TestMapHeader16()
        {
            MsgPackWriter writer = new MsgPackWriter(Allocator.Temp);

            writer.WriteMapHeader(ushort.MaxValue);

            var asArray = writer.ToArray(Allocator.Temp);

            Assert.That(asArray.Length, Is.EqualTo(3));    // should be written as 3 bytes (code + short len)

            MsgPackReader reader = new MsgPackReader(asArray);

            Assert.That(reader.ReadMapHeader(out var len), Is.True);
            Assert.That(len, Is.EqualTo(ushort.MaxValue));
        }
Пример #11
0
        public void TestArrayHeader32()
        {
            MsgPackWriter writer = new MsgPackWriter(Allocator.Temp);

            writer.WriteArrayHeader(int.MaxValue);

            var asArray = writer.ToArray(Allocator.Temp);

            Assert.That(asArray.Length, Is.EqualTo(5));    // should be written as 5 bytes (code + int len)

            MsgPackReader reader = new MsgPackReader(asArray);

            Assert.That(reader.ReadArrayHeader(out var len), Is.True);
            Assert.That(len, Is.EqualTo(int.MaxValue));
        }
Пример #12
0
        public void TestFixedArrayHeader()
        {
            MsgPackWriter writer = new MsgPackWriter(Allocator.Temp);

            writer.WriteArrayHeader(0);
            writer.WriteArrayHeader(0xF);

            var asArray = writer.ToArray(Allocator.Temp);

            Assert.That(asArray.Length, Is.EqualTo(2));    // such small numbers should be stored as fixed numbers

            MsgPackReader reader = new MsgPackReader(asArray);

            Assert.That(reader.ReadArrayHeader(out var len1), Is.True);
            Assert.That(len1, Is.EqualTo(0));

            Assert.That(reader.ReadArrayHeader(out var len2), Is.True);
            Assert.That(len2, Is.EqualTo(0xF));
        }