Exemplo n.º 1
0
        public void Map_CompactEnum()
        {
            var first  = Color.RED;
            var second = Color.GREEN;
            var third  = Color.BLUE;
            var fourth = Color.GREEN;

            var reader = new HessianDataBuilder()
                         .WriteChar('C')
                         .WriteBytes(0x0d).WriteUtf8("example.Color")
                         .WriteBytes(0x91) // one field
                         .WriteBytes(0x04).WriteUtf8("name")

                         .WriteBytes(0x60) // reference definition
                         .WriteBytes(0x03).WriteUtf8("RED")

                         .WriteBytes(0x60)
                         .WriteBytes(0x05).WriteUtf8("GREEN")

                         .WriteBytes(0x60)
                         .WriteBytes(0x04).WriteUtf8("BLUE")

                         .WriteChar('Q').WriteBytes(0x91) //  GREEN

                         .ToReader();

            var input = new HessianInputV2(reader);

            Assert.AreEqual(first, input.ReadObject());
            Assert.AreEqual(second, input.ReadObject());
            Assert.AreEqual(third, input.ReadObject());
            Assert.AreEqual(fourth, input.ReadObject());
        }
Exemplo n.º 2
0
        public void List_Compact_Fixed_UsingTypeRef()
        {
            var first  = new int[] { 0, 1 };
            var second = new int[] { 2, 3, 4 };

            var data = new HessianDataBuilder()
                                                           // first list
                       .WriteBytes(0x72)                   // list tag
                       .WriteBytes(0x04).WriteUtf8("[int") // type
                       .WriteBytes(0x90)                   // int 0
                       .WriteBytes(0x91)                   // int 1
                                                           // second list
                       .WriteBytes(0x73)                   // list tag
                       .WriteBytes(0x90)                   // type ref 0 (above [int)
                       .WriteBytes(0x92)                   // int 2
                       .WriteBytes(0x93)                   // int 3
                       .WriteBytes(0x94);                  // int 4

            var input = new HessianInputV2(data.ToReader());

            CollectionAssert.AreEqual(
                first,
                (IEnumerable)input.ReadObject());

            CollectionAssert.AreEqual(
                second,
                (IEnumerable)input.ReadObject());
        }