public DeserializeItemsIterator(TypeModel model, Stream source, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver, SerializationContext context) { this.haveObject = true; this.source = source; this.type = type; this.style = style; this.expectedField = expectedField; this.resolver = resolver; this.model = model; this.context = context; }
// Token: 0x0600350B RID: 13579 RVA: 0x00133396 File Offset: 0x00131796 public static bool TryDeserializeWithLengthPrefix(Stream source, PrefixStyle style, Serializer.TypeResolver resolver, out object value) { value = RuntimeTypeModel.Default.DeserializeWithLengthPrefix(source, null, null, style, 0, resolver); return(value != null); }
/// <summary> /// Applies a protocol-buffer stream to an existing instance (or null), using length-prefixed /// data - useful with network IO. /// </summary> /// <param name="type">The type being merged.</param> /// <param name="value">The existing instance to be modified (can be null).</param> /// <param name="source">The binary stream to apply to the instance (cannot be null).</param> /// <param name="style">How to encode the length prefix.</param> /// <param name="expectedField">The tag used as a prefix to each record (only used with base-128 style prefixes).</param> /// <param name="resolver">Used to resolve types on a per-field basis.</param> /// <param name="bytesRead">Returns the number of bytes consumed by this operation (includes length-prefix overheads and any skipped data).</param> /// <returns>The updated instance; this may be different to the instance argument if /// either the original instance was null, or the stream defines a known sub-type of the /// original instance.</returns> public object DeserializeWithLengthPrefix(Stream source, object value, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver, out int bytesRead) { bool skip; int len; int tmpBytesRead; bytesRead = 0; do { int actualField; bool expectPrefix = expectedField > 0 || resolver != null; len = ProtoReader.ReadLengthPrefix(source, expectPrefix, style, out actualField, out tmpBytesRead); bytesRead += tmpBytesRead; if (len < 0) { return(value); } if (expectedField == 0 && type == null && resolver != null) { type = resolver(actualField); skip = type == null; } else { skip = expectedField != actualField; } if (skip) { if (len == int.MaxValue) { throw new InvalidOperationException(); } ProtoReader.Seek(source, len, null); bytesRead += len; } } while (skip); int key = GetKey(ref type); if (key < 0) { throw new InvalidOperationException(); } using (ProtoReader reader = new ProtoReader(source, this, len)) { object result = Deserialize(key, value, reader); bytesRead += reader.Position; return(result); } }
/// <summary> /// Applies a protocol-buffer stream to an existing instance (or null), using length-prefixed /// data - useful with network IO. /// </summary> /// <param name="type">The type being merged.</param> /// <param name="value">The existing instance to be modified (can be null).</param> /// <param name="source">The binary stream to apply to the instance (cannot be null).</param> /// <param name="style">How to encode the length prefix.</param> /// <param name="expectedField">The tag used as a prefix to each record (only used with base-128 style prefixes).</param> /// <param name="resolver">Used to resolve types on a per-field basis.</param> /// <returns>The updated instance; this may be different to the instance argument if /// either the original instance was null, or the stream defines a known sub-type of the /// original instance.</returns> public object DeserializeWithLengthPrefix(Stream source, object value, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver) { int bytesRead; return(DeserializeWithLengthPrefix(source, value, type, style, expectedField, resolver, out bytesRead)); }
public IEnumerable DeserializeItems(Stream source, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver, SerializationContext context) { return(new DeserializeItemsIterator(this, source, type, style, expectedField, resolver, context)); }
public IEnumerable DeserializeItems(Stream source, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver) { return(DeserializeItems(source, type, style, expectedField, resolver, null)); }
private object DeserializeWithLengthPrefix(Stream source, object value, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver, out int bytesRead, out bool haveObject, SerializationContext context) { haveObject = false; bytesRead = 0; if (type == null && (style != PrefixStyle.Base128 || resolver == null)) { throw new InvalidOperationException("A type must be provided unless base-128 prefixing is being used in combination with a resolver"); } int num; bool flag2; do { bool flag = expectedField > 0 || resolver != null; num = ProtoReader.ReadLengthPrefix(source, flag, style, out int fieldNumber, out int bytesRead2); if (bytesRead2 == 0) { return(value); } bytesRead += bytesRead2; if (num < 0) { return(value); } if (style == PrefixStyle.Base128) { if (flag && expectedField == 0 && type == null && resolver != null) { type = resolver(fieldNumber); flag2 = (type == null); } else { flag2 = (expectedField != fieldNumber); } } else { flag2 = false; } if (flag2) { if (num == int.MaxValue) { throw new InvalidOperationException(); } ProtoReader.Seek(source, num, null); bytesRead += num; } }while (flag2); ProtoReader protoReader = null; try { protoReader = ProtoReader.Create(source, this, context, num); int key = GetKey(ref type); if (key >= 0 && !Helpers.IsEnum(type)) { value = Deserialize(key, value, protoReader); } else if (!TryDeserializeAuxiliaryType(protoReader, DataFormat.Default, 1, type, ref value, skipOtherFields: true, asListItem: false, autoCreate: true, insideList: false) && num != 0) { ThrowUnexpectedType(type); } bytesRead += protoReader.Position; haveObject = true; return(value); } finally { ProtoReader.Recycle(protoReader); } }
private bool TryDeserializeWithLengthPrefix(Stream source, PrefixStyle style, Serializer.TypeResolver resolver, ref object value) { value = _model.DeserializeWithLengthPrefix(source, value, typeof(TDeserialized), style, 0, resolver); return(value != null); }
private object DeserializeWithLengthPrefix(Stream source, object value, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver, out int bytesRead, out bool haveObject, SerializationContext context) { haveObject = false; bytesRead = 0; if (type == null && (style != PrefixStyle.Base128 || resolver == null)) { throw new InvalidOperationException("A type must be provided unless base-128 prefixing is being used in combination with a resolver"); } while (true) { bool expectPrefix = expectedField > 0 || resolver != null; int actualField; int tmpBytesRead; int len = ProtoReader.ReadLengthPrefix(source, expectPrefix, style, out actualField, out tmpBytesRead); if (tmpBytesRead == 0) { break; } bytesRead += tmpBytesRead; if (len < 0) { return(value); } bool skip; if (style == PrefixStyle.Base128) { if (expectPrefix && expectedField == 0 && type == null && resolver != null) { type = resolver(actualField); skip = (type == null); } else { skip = (expectedField != actualField); } } else { skip = false; } if (skip) { if (len == 2147483647) { goto Block_12; } ProtoReader.Seek(source, len, null); bytesRead += len; } if (!skip) { goto Block_13; } } return(value); Block_12: throw new InvalidOperationException(); Block_13: ProtoReader reader = null; object result; try { int len; reader = ProtoReader.Create(source, this, context, len); int key = this.GetKey(ref type); if (key >= 0 && !Helpers.IsEnum(type)) { value = this.Deserialize(key, value, reader); } else { if (!this.TryDeserializeAuxiliaryType(reader, DataFormat.Default, 1, type, ref value, true, false, true, false) && len != 0) { TypeModel.ThrowUnexpectedType(type); } } bytesRead += reader.Position; haveObject = true; result = value; } finally { ProtoReader.Recycle(reader); } return(result); }
public object DeserializeWithLengthPrefix(Stream source, object value, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver, out int bytesRead) { bool haveObject; return(this.DeserializeWithLengthPrefix(source, value, type, style, expectedField, resolver, out bytesRead, out haveObject, null)); }