Beispiel #1
0
        public void Map_Object()
        {
            var reader = new HessianDataBuilder()
                         // map
                         .WriteChar('M')
                         // type (from the website example)
                         .WriteChar('t').WriteBytes(0, 0x13).WriteUtf8("com.caucho.test.Car")
                         // model field
                         .WriteChar('S').WriteBytes(0, 0x05).WriteUtf8("model")
                         .WriteChar('S').WriteBytes(0, 0x06).WriteUtf8("Beetle")
                         // color field
                         .WriteChar('S').WriteBytes(0, 0x05).WriteUtf8("color")
                         .WriteChar('S').WriteBytes(0, 0x0A).WriteUtf8("aquamarine")
                         // mileage field
                         .WriteChar('S').WriteBytes(0, 0x07).WriteUtf8("mileage")
                         .WriteChar('I').WriteBytes(0, 0x01, 0, 0)
                         // map end
                         .WriteChar('z')
                         .ToReader();

            var expected = new com.caucho.test.Car {
                model = "Beetle", color = "aquamarine", mileage = 65536
            };

            Assert.AreEqual(expected, new HessianInputV1(reader).ReadObject());
        }
Beispiel #2
0
        public void Map_Object()
        {
            var value = new com.caucho.test.Car
            {
                model   = "Beetle",
                color   = "aquamarine",
                mileage = 65536
            };

            var actual = Serialize(value);

            var expected = new HessianDataBuilder()
                           // map
                           .WriteChar('M')
                           // type (from the website example)
                           .WriteChar('t').WriteBytes(0, 0x13).WriteUtf8("com.caucho.test.Car")
                           // model field
                           .WriteChar('S').WriteBytes(0, 0x05).WriteUtf8("model")
                           .WriteChar('S').WriteBytes(0, 0x06).WriteUtf8("Beetle")
                           // color field
                           .WriteChar('S').WriteBytes(0, 0x05).WriteUtf8("color")
                           .WriteChar('S').WriteBytes(0, 0x0A).WriteUtf8("aquamarine")
                           // mileage field
                           .WriteChar('S').WriteBytes(0, 0x07).WriteUtf8("mileage")
                           .WriteChar('I').WriteBytes(0, 0x01, 0, 0)
                           // map end
                           .WriteChar('z')
                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
        public void Map_Object()
        {
            var reader = new HessianDataBuilder()
                         .WriteChar('M')                                    // map

                         .WriteBytes(0x13).WriteUtf8("com.caucho.test.Car") // type

                         .WriteBytes(0x05).WriteUtf8("model")
                         .WriteBytes(0x06).WriteUtf8("Beetle")

                         .WriteBytes(0x05).WriteUtf8("color")
                         .WriteBytes(0x0a).WriteUtf8("aquamarine")

                         .WriteBytes(0x07).WriteUtf8("mileage")
                         .WriteChar('I').WriteBytes(0, 0x01, 0, 0)

                         .WriteChar('Z') // map end
                         .ToReader();

            var expected = new com.caucho.test.Car
            {
                model   = "Beetle",
                color   = "aquamarine",
                mileage = 65536
            };

            Assert.AreEqual(expected, new HessianInputV2(reader).ReadObject());
        }
        public void Map_CompactObject()
        {
            var reader = new HessianDataBuilder()
                         .WriteChar('C')   // definition
                         .WriteBytes(0x13).WriteUtf8("com.caucho.test.Car")
                         .WriteBytes(0x93) // 3 fields
                         .WriteBytes(0x05).WriteUtf8("model")
                         .WriteBytes(0x05).WriteUtf8("color")
                         .WriteBytes(0x07).WriteUtf8("mileage")

                         .WriteBytes(0x60) // instance
                         .WriteBytes(0x06).WriteUtf8("Beetle")
                         .WriteBytes(0x0a).WriteUtf8("aquamarine")
                         .WriteChar('I').WriteBytes(0, 0x01, 0, 0)

                         .ToReader();

            var expected = new com.caucho.test.Car
            {
                model   = "Beetle",
                color   = "aquamarine",
                mileage = 65536
            };

            Assert.AreEqual(expected, new HessianInputV2(reader).ReadObject());
        }
Beispiel #5
0
        public void Map_CompactObject()
        {
            var value = new com.caucho.test.Car
            {
                model   = "Beetle",
                color   = "aquamarine",
                mileage = 268435456
            };

            var actual = Serialize(value);

            var expected = new HessianDataBuilder()
                           .WriteChar('C')   // definition
                           .WriteBytes(0x13).WriteUtf8("com.caucho.test.Car")
                           .WriteBytes(0x93) // 3 fields
                           .WriteBytes(0x05).WriteUtf8("model")
                           .WriteBytes(0x05).WriteUtf8("color")
                           .WriteBytes(0x07).WriteUtf8("mileage")

                           .WriteBytes(0x60) // instance
                           .WriteBytes(0x06).WriteUtf8("Beetle")
                           .WriteBytes(0x0a).WriteUtf8("aquamarine")
                           .WriteChar('I').WriteBytes(0x10, 0, 0, 0)

                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }