public override TestTarget Deserialize(ref MessagePackReader reader) { if (!reader.TryReadNil()) { var value = new TestTarget(); int count = reader.ReadMapHeader(); for (int i = 0; i < count; i++) { ArraySegment<byte> segment = reader.ReadStringSegment(); if (m_nameToKey.TryGetValue(segment.Array, segment.Offset, segment.Count, out int key)) { switch (key) { case 0: { value.BoolValue = reader.ReadBoolean(); break; } case 1: { value.IntValue = reader.ReadInt32(); break; } case 2: { value.FloatValue = reader.ReadSingle(); break; } case 3: { value.StringValue = reader.ReadString(); break; } case 4: { value.EnumValue = m_formatterTypeCode.Deserialize(ref reader); break; } default: { reader.ReadNextBlock(); break; } } } else { reader.ReadNextBlock(); } } } return default; }
public object Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return(null); } if (reader.NextMessagePackType == MessagePackType.Extension) { ExtensionHeader ext = reader.ReadExtensionFormatHeader(); if (ext.TypeCode == TypelessFormatter.ExtensionTypeCode) { // it has type name serialized ReadOnlySequence <byte> typeName = reader.ReadStringSegment(); ArraySegment <byte> typeNameArraySegment; byte[] rented = null; if (!typeName.IsSingleSegment || !MemoryMarshal.TryGetArray(typeName.First, out typeNameArraySegment)) { rented = ArrayPool <byte> .Shared.Rent((int)typeName.Length); typeName.CopyTo(rented); typeNameArraySegment = new ArraySegment <byte>(rented, 0, (int)typeName.Length); } var result = this.DeserializeByTypeName(typeNameArraySegment, ref reader, options); if (rented != null) { ArrayPool <byte> .Shared.Return(rented); } return(result); } } // fallback return(Resolvers.TypelessFormatterFallbackResolver.Instance.GetFormatter <object>().Deserialize(ref reader, options)); }
public void StringSegmentTest(string target) { (MemoryStream stream, MsgPack.Packer packer) = this.CreateReferencePacker(); var sequence = new Sequence <byte>(); var writer = new MessagePackWriter(sequence); writer.Write(target); writer.Flush(); var returnLength = sequence.Length; MsgPack.Packer referencePacked = packer.PackString(target); referencePacked.Position.Is(returnLength); stream.ToArray().SequenceEqual(sequence.AsReadOnlySequence.ToArray()).IsTrue(); var sequenceReader = new MessagePackReader(sequence.AsReadOnlySequence); var segment = sequenceReader.ReadStringSegment().Value.ToArray(); Encoding.UTF8.GetString(segment).Is(target); sequenceReader.End.IsTrue(); this.CreateUnpackedReference(sequence).AsStringUtf8().Is(target); }
public Guid Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { ReadOnlySequence <byte> segment = reader.ReadStringSegment(); if (segment.Length != 36) { throw new InvalidOperationException("Unexpected length of string."); } GuidBits result; if (segment.IsSingleSegment) { result = new GuidBits(segment.First.Span); } else { Span <byte> bytes = stackalloc byte[36]; segment.CopyTo(bytes); result = new GuidBits(bytes); } return(result.Value); }
public global::PerfBenchmarkDotNet.StringKeySerializerTarget Deserialize(ref MessagePackReader reader, newmsgpack::MessagePack.MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return(null); } var length = reader.ReadMapHeader(); var __MyProperty1__ = default(int); var __MyProperty2__ = default(int); var __MyProperty3__ = default(int); var __MyProperty4__ = default(int); var __MyProperty5__ = default(int); var __MyProperty6__ = default(int); var __MyProperty7__ = default(int); var __MyProperty8__ = default(int); var __MyProperty9__ = default(int); for (int i = 0; i < length; i++) { ReadOnlySequence <byte> stringKey = reader.ReadStringSegment(); int key; if (!this.keyMapping.TryGetValue(stringKey, out key)) { reader.Skip(); continue; } switch (key) { case 0: __MyProperty1__ = reader.ReadInt32(); break; case 1: __MyProperty2__ = reader.ReadInt32(); break; case 2: __MyProperty3__ = reader.ReadInt32(); break; case 3: __MyProperty4__ = reader.ReadInt32(); break; case 4: __MyProperty5__ = reader.ReadInt32(); break; case 5: __MyProperty6__ = reader.ReadInt32(); break; case 6: __MyProperty7__ = reader.ReadInt32(); break; case 7: __MyProperty8__ = reader.ReadInt32(); break; case 8: __MyProperty9__ = reader.ReadInt32(); break; default: reader.Skip(); break; } } var ____result = new global::PerfBenchmarkDotNet.StringKeySerializerTarget(); ____result.MyProperty1 = __MyProperty1__; ____result.MyProperty2 = __MyProperty2__; ____result.MyProperty3 = __MyProperty3__; ____result.MyProperty4 = __MyProperty4__; ____result.MyProperty5 = __MyProperty5__; ____result.MyProperty6 = __MyProperty6__; ____result.MyProperty7 = __MyProperty7__; ____result.MyProperty8 = __MyProperty8__; ____result.MyProperty9 = __MyProperty9__; return(____result); }
public StringKeySerializerTarget Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return(null); } int num3 = reader.ReadMapHeader(); int myProperty = 0; int myProperty2 = 0; int myProperty3 = 0; int myProperty4 = 0; int myProperty5 = 0; int myProperty6 = 0; int myProperty7 = 0; int myProperty8 = 0; int myProperty9 = 0; for (int i = 0; i < num3; i++) { int num4; ReadOnlySequence <byte> segment = reader.ReadStringSegment(); bool arg_47_0 = this.keyMapping.TryGetValue(segment, out num4); if (!arg_47_0) { reader.Skip(); } else { switch (num4) { case 0: myProperty = reader.ReadInt32(); break; case 1: myProperty2 = reader.ReadInt32(); break; case 2: myProperty3 = reader.ReadInt32(); break; case 3: myProperty4 = reader.ReadInt32(); break; case 4: myProperty5 = reader.ReadInt32(); break; case 5: myProperty6 = reader.ReadInt32(); break; case 6: myProperty7 = reader.ReadInt32(); break; case 7: myProperty8 = reader.ReadInt32(); break; case 8: myProperty9 = reader.ReadInt32(); break; default: reader.Skip(); break; } } } return(new StringKeySerializerTarget { MyProperty1 = myProperty, MyProperty2 = myProperty2, MyProperty3 = myProperty3, MyProperty4 = myProperty4, MyProperty5 = myProperty5, MyProperty6 = myProperty6, MyProperty7 = myProperty7, MyProperty8 = myProperty8, MyProperty9 = myProperty9, }); }