UnpackDictionary() public static method

Unpacks the dictionary value from the specified Stream.

The processed bytes count can be calculated via P:Stream.Position of source when the P:Stream.CanSeek is true.

When the type of packed value is not known, use UnpackObject(Stream) instead.

/// is null. /// /// The of is false. /// /// is not valid MessagePack stream. /// Note that the state of will be unpredictable espicially it is not seekable. /// /// The unpacked result in the is not compatible to . /// Note that the state of will be unpredictable espicially it is not seekable. /// /// The items count of the underlying collection body is over . ///
public static UnpackDictionary ( Stream source ) : MessagePackObjectDictionary
source Stream The which contains Message Pack binary stream.
return MessagePackObjectDictionary
        public void TestUnpackDictionary_ByteArray_Null_Nil()
        {
            var result = Unpacking.UnpackDictionary(new byte[] { 0xC0 });

            Assert.AreEqual(1, result.ReadCount);
            Assert.IsNull(result.Value);
        }
        public void TestUnpackDictionary_ByteArray_Map32MinValue_AsMap32_AsIs()
        {
            var result = Unpacking.UnpackDictionary(new byte[] { 0xDF, 0x00, 0x01, 0x00, 0x00 }.Concat(CreateDictionaryBodyBinary(0x10000)).ToArray());

            Assert.AreEqual(393221, result.ReadCount);
            Assert.AreEqual(0x10000, result.Value.Count);
            for (int i = 0; i < result.Value.Count; i++)
            {
                MessagePackObject value;
                Assert.IsTrue(result.Value.TryGetValue(i + 1, out value));
                Assert.IsTrue(value.Equals(0x57));
            }
        }
        public void TestUnpackDictionary_ByteArray_FixMap0Value_AsFixMap0_AsIs()
        {
            var result = Unpacking.UnpackDictionary(new byte[] { 0x80 });

            Assert.AreEqual(1, result.ReadCount);
            Assert.AreEqual(0, result.Value.Count);
            for (int i = 0; i < result.Value.Count; i++)
            {
                MessagePackObject value;
                Assert.IsTrue(result.Value.TryGetValue(i + 1, out value));
                Assert.IsTrue(value.Equals(0x57));
            }
        }
        public void TestUnpackDictionary_ByteArray_FixMapMaxValue_AsMap16_AsIs()
        {
            var result = Unpacking.UnpackDictionary(new byte[] { 0xDE, 0x00, 0x0F }.Concat(CreateDictionaryBodyBinary(0xF)).ToArray());

            Assert.AreEqual(93, result.ReadCount);
            Assert.AreEqual(0xF, result.Value.Count);
            for (int i = 0; i < result.Value.Count; i++)
            {
                MessagePackObject value;
                Assert.IsTrue(result.Value.TryGetValue(i + 1, out value));
                Assert.IsTrue(value.Equals(0x57));
            }
        }
 public void TestUnpackDictionary_Stream_FixMap0Value_AsFixMap0_AsIs()
 {
     using (var buffer = new MemoryStream(new byte[] { 0x80 }))
     {
         var result = Unpacking.UnpackDictionary(buffer);
         Assert.AreEqual(1, buffer.Position);
         Assert.AreEqual(0, result.Count);
         for (int i = 0; i < result.Count; i++)
         {
             MessagePackObject value;
             Assert.IsTrue(result.TryGetValue(i + 1, out value));
             Assert.IsTrue(value.Equals(0x57));
         }
     }
 }
 public void TestUnpackDictionary_Stream_Map32MinValue_AsMap32_AsIs()
 {
     using (var buffer = new MemoryStream(new byte[] { 0xDF, 0x00, 0x01, 0x00, 0x00 }.Concat(CreateDictionaryBodyBinary(0x10000)).ToArray()))
     {
         var result = Unpacking.UnpackDictionary(buffer);
         Assert.AreEqual(393221, buffer.Position);
         Assert.AreEqual(0x10000, result.Count);
         for (int i = 0; i < result.Count; i++)
         {
             MessagePackObject value;
             Assert.IsTrue(result.TryGetValue(i + 1, out value));
             Assert.IsTrue(value.Equals(0x57));
         }
     }
 }
 public void TestUnpackDictionary_Stream_FixMapMaxValue_AsFixMap15_AsIs()
 {
     using (var buffer = new MemoryStream(new byte[] { 0x8F }.Concat(CreateDictionaryBodyBinary(0xF)).ToArray()))
     {
         var result = Unpacking.UnpackDictionary(buffer);
         Assert.AreEqual(91, buffer.Position);
         Assert.AreEqual(0xF, result.Count);
         for (int i = 0; i < result.Count; i++)
         {
             MessagePackObject value;
             Assert.IsTrue(result.TryGetValue(i + 1, out value));
             Assert.IsTrue(value.Equals(0x57));
         }
     }
 }
Beispiel #8
0
 public void TestUnpackDictionary_KeyDuplicated()
 {
     Assert.Throws <InvalidMessagePackStreamException>(() => Unpacking.UnpackDictionary(new byte[] { 0x82, 0x1, 0x0, 0x1, 0x0 }));
 }
Beispiel #9
0
 public void TestUnpackDictionary_DictionaryCountIsGreaterThanInt32MaxValue()
 {
     Assert.Throws <MessageNotSupportedException>(() => Unpacking.UnpackDictionary(new byte[] { 0xDF, 0x80, 0x00, 0x00, 0x00, 0xFF }));
 }
 public void TestUnpackDictionary_ByteArray_NotMap()
 {
     Assert.Throws <MessageTypeException>(() => Unpacking.UnpackDictionary(new byte[] { 0x1 }));
 }