예제 #1
0
        public char ReadChar()
        {
            char value = MessagePackBinary.ReadChar(Buffer, Position, out int readSize);

            Position += readSize;

            return(value);
        }
예제 #2
0
        public char?Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }

            return(MessagePackBinary.ReadChar(bytes, offset, out readSize));
        }
 public Char?Deserialize(byte[] bytes, int offset, out int readSize)
 {
     if (MessagePackBinary.IsNil(bytes, offset))
     {
         readSize = 1;
         return(null);
     }
     else
     {
         return(MessagePackBinary.ReadChar(bytes, offset, out readSize));
     }
 }
        public Char[] Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
        {
            if (MessagePackBinary.IsNil(bytes, offset))
            {
                readSize = 1;
                return(null);
            }
            else
            {
                var startOffset = offset;

                var len = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);
                offset += readSize;
                var array = new Char[len];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = MessagePackBinary.ReadChar(bytes, offset, out readSize);
                    offset  += readSize;
                }
                readSize = offset - startOffset;
                return(array);
            }
        }
예제 #5
0
 public Char Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
 {
     return(MessagePackBinary.ReadChar(bytes, offset, out readSize));
 }
        public void Read()
        {
            void Check1 <T, T2>(T data, T2 result, Func <Stream, T2> streamRead)
            {
                const int CheckOffset = 10;

                byte[] bytes = null;
                var    len   = MessagePack.Resolvers.StandardResolver.Instance.GetFormatter <T>().Serialize(ref bytes, CheckOffset, data, MessagePack.Resolvers.StandardResolver.Instance);

                MessagePackBinary.FastResize(ref bytes, CheckOffset + len);


                var ms = new MemoryStream(bytes);

                ms.Position = CheckOffset;

                streamRead(ms).Is(result);
            }

            void Check2 <T>(T data, Func <Stream, T> streamRead)
            {
                const int CheckOffset = 10;

                byte[] bytes = null;
                var    len   = MessagePack.Resolvers.StandardResolver.Instance.GetFormatter <T>().Serialize(ref bytes, CheckOffset, data, MessagePack.Resolvers.StandardResolver.Instance);

                MessagePackBinary.FastResize(ref bytes, CheckOffset + len);


                var ms = new MemoryStream(bytes);

                ms.Position = CheckOffset;

                streamRead(ms).Is(data);
            }

            Check1(new[] { 1, 10, 100, 1000, 10000, short.MaxValue, int.MaxValue }, 7, x => MessagePackBinary.ReadArrayHeader(x));
            Check1(new[] { 1, 10, 100, 1000, 10000, short.MaxValue, int.MaxValue }, (uint)7, x => MessagePackBinary.ReadArrayHeaderRaw(x));
            Check1(Nil.Default, true, x => MessagePackBinary.IsNil((x)));
            Check2(true, x => MessagePackBinary.ReadBoolean(x));
            Check2((byte)100, x => MessagePackBinary.ReadByte(x));
            Check2(new byte[] { 1, 10, 100, 245 }, x => MessagePackBinary.ReadBytes(x));
            Check2('あ', x => MessagePackBinary.ReadChar(x));
            Check2(DateTime.UtcNow, x => MessagePackBinary.ReadDateTime(x));
            Check2(132, x => MessagePackBinary.ReadInt16(x));
            Check2(423, x => MessagePackBinary.ReadInt32(x));
            Check2(64332, x => MessagePackBinary.ReadInt64(x));
            Check2(Nil.Default, x => MessagePackBinary.ReadNil(x));
            Check2(11, x => MessagePackBinary.ReadSByte(x));
            Check2(10.31231f, x => MessagePackBinary.ReadSingle(x));
            Check2("foobar", x => MessagePackBinary.ReadString(x));
            Check2(124, x => MessagePackBinary.ReadUInt16(x));
            Check2((uint)432, x => MessagePackBinary.ReadUInt32(x));
            Check2((ulong)432, x => MessagePackBinary.ReadUInt64(x));


            Check1(new Dictionary <int, int>()
            {
                { 1, 2 }
            }, 1, x => MessagePackBinary.ReadMapHeader(x));
            Check1(new Dictionary <int, int>()
            {
                { 1, 2 }
            }, (uint)1, x => MessagePackBinary.ReadMapHeaderRaw(x));

            {
                var block  = new object[] { 1, new[] { 1, 10, 100 }, 100 };
                var bytes  = MessagePackSerializer.Serialize(block);
                var stream = new MemoryStream(bytes);
                MessagePackBinary.ReadNext(stream);      // array(first)
                MessagePackBinary.ReadNext(stream);      // int
                MessagePackBinary.ReadNextBlock(stream); // skip array
                MessagePackBinary.ReadInt32(stream).Is(100);
            }
            {
                var block = new object[] { 1, new Dictionary <int, int> {
                                               { 1, 10 }, { 111, 200 }
                                           }, 100 };
                var bytes  = MessagePackSerializer.Serialize(block);
                var stream = new MemoryStream(bytes);
                MessagePackBinary.ReadNext(stream);
                MessagePackBinary.ReadNext(stream);
                MessagePackBinary.ReadNextBlock(stream);
                MessagePackBinary.ReadInt32(stream).Is(100);
            }
        }