Ejemplo n.º 1
0
        public void List_Compact_Fixed_UsingTypeRef()
        {
            var first  = new int[] { 0, 1 };
            var second = new int[] { 2, 3, 4 };

            var expected = 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
                           .ToArray();

            byte[] actual;
            using (var ms = new MemoryStream())
                using (var writer = new HessianStreamWriter(ms))
                {
                    var output = new HessianOutputV2(writer, TypeBindings.Java);
                    output.WriteObject(first);
                    output.WriteObject(second);
                    actual = ms.ToArray();
                }

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void Map_CompactEnum()
        {
            var first  = Color.RED;
            var second = Color.GREEN;
            var third  = Color.BLUE;
            var fourth = Color.GREEN;

            byte[] actual;
            using (var ms = new MemoryStream())
                using (var writer = new HessianStreamWriter(ms))
                {
                    var output = new HessianOutputV2(writer);

                    output.WriteObject(first);
                    output.WriteObject(second);
                    output.WriteObject(third);
                    output.WriteObject(fourth);

                    actual = ms.ToArray();
                }

            var expected = 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

                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }