Exemple #1
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));
        }
 public static void WriteException(MsgPackWriter writer, Exception error)
 {
     if (error != null)
     {
         writer.WriteArrayHeader(3);
         writer.WriteString("DotnetException");
         writer.WriteString(error.Message);
         writer.WriteString(error.StackTrace);
     }
     else
     {
         writer.WriteNil();
     }
 }
Exemple #3
0
 public void BeginContainer(int size)
 {
     DecSpace();
     space.Push(size);
     //special 'unspecified' case
     if (size == -1)
     {
         io.Write(-1);
     }
     else
     {
         io.WriteArrayHeader(size);
     }
 }
Exemple #4
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));
        }