public object Read(object value, ProtoReader source) { ProtoReader.ExpectRoot(source); if (_protoCompatibility) { return(_serializer.Read(value, source)); } int typeKey; object obj; int expectedRefKey; var rootToken = ProtoReader.StartSubItem(source); int formatVersion = source.ReadFieldHeader(); if (formatVersion != CurrentFormatVersion) { throw new ProtoException("Wrong format version, required " + CurrentFormatVersion + " but actual " + formatVersion); } var r = _serializer.Read(value, source); while (ProtoReader.TryGetNextLateReference(out typeKey, out obj, out expectedRefKey, source)) { int actualRefKey; do { actualRefKey = source.ReadFieldHeader() - 1; if (actualRefKey != expectedRefKey) { if (actualRefKey <= -1) { throw new ProtoException("Expected field for late reference"); } // should go only up if (actualRefKey > expectedRefKey) { throw new ProtoException("Mismatched order of late reference objects"); } source.SkipField(); // refKey < num } } while (actualRefKey < expectedRefKey); object lateObj = ProtoReader.ReadObject(obj, typeKey, source); if (!ReferenceEquals(lateObj, obj)) { throw new ProtoException("Late reference changed during deserializing"); } } ProtoReader.EndSubItem(rootToken, true, source); return(r); }
object IProtoSerializer.Read(object value, ProtoReader source) { return(ProtoReader.ReadObject(value, key, source)); }
object IProtoSerializer.Read(ProtoReader source, ref ProtoReader.State state, object value) { return(ProtoReader.ReadObject(value, key, source, ref state)); }
public object Read(object value, ProtoReader source) { var type = ExpectedType; if (source.WireType == WireType.Null) { return(Helpers.IsValueType(type) ? Activator.CreateInstance(type) : null); } if (!RequiresOldValue) { value = null; } bool shouldEnd; int newTypeRefKey; int newObjectKey; int typeKey = _baseKey; bool isDynamic; bool isLateReference; BclHelpers.NetObjectOptions options = _options; SubItemToken token = NetObjectHelpers.ReadNetObject_Start( ref value, source, ref type, options, out isDynamic, out isLateReference, ref typeKey, out newObjectKey, out newTypeRefKey, out shouldEnd); if (shouldEnd) { object oldValue = value; if (typeKey >= 0) { // can be only for builtins options &= ~BclHelpers.NetObjectOptions.LateSet; if (typeKey == _baseKey && _baseKeySerializer != null) { if (isLateReference) { if (_lateReferenceTail == null) { throw new ProtoException("Late reference can't be deserialized for type " + ExpectedType.Name); } value = _lateReferenceTail.Read(value, source); } else { value = _baseKeySerializer.Read(value, source); } } else { Debug.Assert(isDynamic); value = ProtoReader.ReadObject(value, typeKey, source); } } else { if (isDynamic) { if (source.TryReadBuiltinType(ref value, Helpers.GetTypeCode(type), true)) { options |= BclHelpers.NetObjectOptions.LateSet; } else { throw new ProtoException("Dynamic type is not a contract-type: " + type.Name); } } else { if (isLateReference) { if (_lateReferenceTail == null) { throw new ProtoException("Late reference can't be deserialized for type " + ExpectedType.Name); } value = _lateReferenceTail.Read(value, source); } else { if (_tail == null) { throw new ProtoException("Dynamic type expected but no type info was read"); } else { // ensure consistent behavior with emit version value = _tail.Read(_tail.RequiresOldValue ? value : null, source); } } } } NetObjectHelpers.ReadNetObject_EndWithNoteNewObject(value, source, oldValue, type, newObjectKey, newTypeRefKey, options, token); } else { if (Helpers.IsValueType(ExpectedType) && value == null) { value = Activator.CreateInstance(ExpectedType); } ProtoReader.EndSubItem(token, source); } return(value); }
object ProtoBuf.Serializers.IProtoSerializer.Read(object value, ProtoReader source) { return(ProtoReader.ReadObject(value, this.key, source)); }