Ejemplo n.º 1
0
        public async Task BasicStringSerialization()
        {
            byte[] serializedStream;
            var    stringToPush = "Test";

            using (var stream = new MemoryStream())
                using (var serializer = new BigObjectSerializer(stream))
                {
                    serializer.PushString(stringToPush);
                    serializer.Flush();

                    serializedStream = stream.ToArray();
                }

            using (var stream = new MemoryStream(serializedStream))
                using (var deserializer = new BigObjectDeserializer(stream))
                {
                    var stringVal = deserializer.PopString();

                    Assert.Equal(stringToPush, stringVal);
                }
        }
Ejemplo n.º 2
0
        public async Task BasicSerialization()
        {
            byte[] serializedStream;

            int    intToPush    = 1;
            bool   boolToPush   = true;
            short  shortToPush  = 16;
            string stringToPush = "test";
            byte   byteToPush   = 0x3F;
            ushort ushortToPush = 17;
            uint   uintToPush   = 18;
            long   longToPush   = 400000000000000L;
            ulong  ulongToPush  = 400000000000001UL;
            float  floatToPush  = 1.5f;
            double doubleToPush = 15.3d;

            using (var stream = new MemoryStream())
                using (var serializer = new BigObjectSerializer(stream))
                {
                    serializer.PushInt(intToPush);
                    serializer.PushBool(boolToPush);
                    serializer.PushShort(shortToPush);
                    serializer.PushString(stringToPush);
                    serializer.PushByte(byteToPush);
                    serializer.PushUnsignedShort(ushortToPush);
                    serializer.PushUnsignedInt(uintToPush);
                    serializer.PushLong(longToPush);
                    serializer.PushUnsignedLong(ulongToPush);
                    serializer.PushFloat(floatToPush);
                    serializer.PushDouble(doubleToPush);
                    serializer.Flush();

                    serializedStream = stream.ToArray();
                }

            using (var stream = new MemoryStream(serializedStream))
                using (var deserializer = new BigObjectDeserializer(stream))
                {
                    var intVal    = deserializer.PopInt();
                    var boolVal   = deserializer.PopBool();
                    var shortVal  = deserializer.PopShort();
                    var stringVal = deserializer.PopString();
                    var byteVal   = deserializer.PopByte();
                    var ushortVal = deserializer.PopUnsignedShort();
                    var uintVal   = deserializer.PopUnsignedInt();
                    var longVal   = deserializer.PopLong();
                    var ulongVal  = deserializer.PopUnsignedLong();
                    var floatVal  = deserializer.PopFloat();
                    var doubleVal = deserializer.PopDouble();

                    Assert.Equal(intToPush, intVal);
                    Assert.Equal(boolToPush, boolVal);
                    Assert.Equal(shortToPush, shortVal);
                    Assert.Equal(stringToPush, stringVal);
                    Assert.Equal(byteToPush, byteVal);
                    Assert.Equal(ushortToPush, ushortVal);
                    Assert.Equal(uintToPush, uintVal);
                    Assert.Equal(longToPush, longVal);
                    Assert.Equal(ulongToPush, ulongVal);
                    Assert.Equal(floatToPush, floatVal);
                    Assert.Equal(doubleToPush, doubleVal);
                }
        }