public void OldSpecBinary()
        {
            var referenceContext = new MsgPack.Serialization.SerializationContext(MsgPack.PackerCompatibilityOptions.Classic)
            {
                DefaultDateTimeConversionMethod = MsgPack.Serialization.DateTimeConversionMethod.Native,
            };

            var data = Enumerable.Range(0, 10000).Select(x => (byte)1).ToArray();

            MsgPack.Serialization.MessagePackSerializer <byte[]> serializer = referenceContext.GetSerializer <byte[]>();

            using (var sequence = new Sequence <byte>())
            {
                var oldSpecWriter = new MessagePackWriter(sequence)
                {
                    OldSpec = true
                };
                MessagePackSerializer.Serialize(ref oldSpecWriter, data);
                oldSpecWriter.Flush();
                var a = sequence.AsReadOnlySequence.ToArray();
                var b = serializer.PackSingleObject(data);

                a.Is(b);

                var oldSpecReader = new MessagePackReader(sequence.AsReadOnlySequence);
                var r1            = MessagePackSerializer.Deserialize <byte[]>(ref oldSpecReader);
                var r2            = serializer.UnpackSingleObject(b);

                r1.Is(r2);
            }
        }
        public void OldSpecString()
        {
            var referenceContext = new MsgPack.Serialization.SerializationContext(MsgPack.PackerCompatibilityOptions.Classic)
            {
                DefaultDateTimeConversionMethod = MsgPack.Serialization.DateTimeConversionMethod.Native,
            };

            var data = "あいうえおabcdefgかきくけこあいうえおabcdefgかきくけこあいうえおabcdefgかきくけこあいうえおabcdefgかきくけこ"; // Japanese

            MsgPack.Serialization.MessagePackSerializer <string> serializer = referenceContext.GetSerializer <string>();

            using (var sequence = new Sequence <byte>())
            {
                var oldSpecWriter = new MessagePackWriter(sequence)
                {
                    OldSpec = true
                };
                MessagePackSerializer.Serialize(ref oldSpecWriter, data);
                oldSpecWriter.Flush();
                var a = sequence.AsReadOnlySequence.ToArray();
                var b = serializer.PackSingleObject(data);

                a.Is(b);

                var oldSpecReader = new MessagePackReader(sequence.AsReadOnlySequence);
                var r1            = MessagePackSerializer.Deserialize <string>(ref oldSpecReader);
                var r2            = serializer.UnpackSingleObject(b);

                r1.Is(r2);
            }
        }
Exemplo n.º 3
0
 public static List <Tuple <byte[], byte[]> > Pack(List <Tuple <Types.Outpoint, Types.Output> > list)
 {
     return(new List <Tuple <byte[], byte[]> >(list.Select(
                                                   t => new Tuple <byte[], byte[]>(
                                                       outpointSerializer.PackSingleObject(t.Item1),
                                                       outputSerializer.PackSingleObject(t.Item2)
                                                       ))));
 }
        public void NativeDateTime()
        {
            var referenceContext = new MsgPack.Serialization.SerializationContext(MsgPack.PackerCompatibilityOptions.Classic)
            {
                DefaultDateTimeConversionMethod = MsgPack.Serialization.DateTimeConversionMethod.Native,
            };

            DateTime now = DateTime.Now;

            MsgPack.Serialization.MessagePackSerializer <DateTime> serializer = referenceContext.GetSerializer <DateTime>();

            var a = MessagePackSerializer.Serialize(now, NativeDateTimeResolver.Options);
            var b = serializer.PackSingleObject(now);

            a.Is(b);

            DateTime dt1 = MessagePackSerializer.Deserialize <DateTime>(a, NativeDateTimeResolver.Options);
            DateTime dt2 = serializer.UnpackSingleObject(b);

            dt1.Is(dt2);
        }