/// <summary> /// Parses a decimal from a protobuf stream /// </summary> public static decimal ReadDecimal(ProtoReader reader) { ulong low = 0; uint high = 0; uint signScale = 0; int fieldNumber; SubItemToken token = ProtoReader.StartSubItem(reader); while ((fieldNumber = reader.ReadFieldHeader()) > 0) { switch (fieldNumber) { case FieldDecimalLow: low = reader.ReadUInt64(); break; case FieldDecimalHigh: high = reader.ReadUInt32(); break; case FieldDecimalSignScale: signScale = reader.ReadUInt32(); break; default: reader.SkipField(); break; } } ProtoReader.EndSubItem(token, reader); int lo = (int)(low & 0xFFFFFFFFL), mid = (int)((low >> 32) & 0xFFFFFFFFL), hi = (int)high; bool isNeg = (signScale & 0x0001) == 0x0001; byte scale = (byte)((signScale & 0x01FE) >> 1); return(new decimal(lo, mid, hi, isNeg, scale)); }
public override object Read(object value, ProtoReader source) { int field = source.FieldNumber; BasicList list = new BasicList(); if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(packedWireType, source)) { list.Add(Tail.Read(null, source)); } ProtoReader.EndSubItem(token, source); } else { do { list.Add(Tail.Read(null, source)); } while (source.TryReadFieldHeader(field)); } int oldLen = AppendToCollection ? ((value == null ? 0 : ((Array)value).Length)) : 0; Array result = Array.CreateInstance(itemType, oldLen + list.Count); if (oldLen != 0) { ((Array)value).CopyTo(result, 0); } list.CopyTo(result, oldLen); return(result); }
/// <summary> /// Parses a TimeSpan from a protobuf stream using the standardized format, google.protobuf.Duration /// </summary> public static TimeSpan ReadDuration(ProtoReader source) { long seconds = 0; int nanos = 0; SubItemToken token = ProtoReader.StartSubItem(source); int fieldNumber; while ((fieldNumber = source.ReadFieldHeader()) > 0) { switch (fieldNumber) { case 1: seconds = source.ReadInt64(); break; case 2: nanos = source.ReadInt32(); break; default: source.SkipField(); break; } } ProtoReader.EndSubItem(token, source); return(FromDurationSeconds(seconds, nanos)); }
public object Read(object value, ProtoReader source) { UnityEngine.LayerMask data = (UnityEngine.LayerMask)value; int fieldNumber = 0; SubItemToken token = ProtoReader.StartSubItem(source); while ((fieldNumber = source.ReadFieldHeader()) != 0) { switch (fieldNumber) { case 1: data.value = source.ReadInt32(); break; default: source.SkipField(); break; } } ProtoReader.EndSubItem(token, source); return(data); }
public override object Read(object value, ProtoReader source) { int field = source.FieldNumber; BasicList basicList = new BasicList(); if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(packedWireType, source)) { basicList.Add(base.Tail.Read(null, source)); } ProtoReader.EndSubItem(token, source); } else { do { basicList.Add(base.Tail.Read(null, source)); }while (source.TryReadFieldHeader(field)); } int num = AppendToCollection ? ((value != null) ? ((Array)value).Length : 0) : 0; Array array = Array.CreateInstance(itemType, num + basicList.Count); if (num != 0) { ((Array)value).CopyTo(array, 0); } basicList.CopyTo(array, num); return(array); }
private static void Merge(ProtoReader reader, ref ProtoReader.State state, ref protogen.Database obj) { SubItemToken tok; int field; if (obj == null) { obj = new protogen.Database(); } while ((field = reader.ReadFieldHeader(ref state)) != 0) { switch (field) { case 1: do { protogen.Order _1 = default; tok = ProtoReader.StartSubItem(reader, ref state); Merge(reader, ref state, ref _1); ProtoReader.EndSubItem(tok, reader, ref state); obj.Orders.Add(_1); } while (reader.TryReadFieldHeader(ref state, 1)); break; default: reader.AppendExtensionData(ref state, obj); break; } } }
public override object Read(ProtoReader source, ref ProtoReader.State state, object value) { TDictionary typed = (AppendToCollection ? ((TDictionary)value) : null) ?? (TDictionary)Activator.CreateInstance(concreteType); do { var key = DefaultKey; var typedValue = DefaultValue; SubItemToken token = ProtoReader.StartSubItem(source, ref state); int field; while ((field = source.ReadFieldHeader(ref state)) > 0) { switch (field) { case 1: key = (TKey)keyTail.Read(source, ref state, null); break; case 2: typedValue = (TValue)Tail.Read(source, ref state, Tail.RequiresOldValue ? (object)typedValue : null); break; default: source.SkipField(ref state); break; } } ProtoReader.EndSubItem(token, source, ref state); typed[key] = typedValue; } while (source.TryReadFieldHeader(ref state, fieldNumber)); return(typed); }
public override object Read(object value, ProtoReader source) { int fieldNumber = source.FieldNumber; BasicList list = new BasicList(); if ((this.packedWireType != WireType.None) && (source.WireType == WireType.String)) { SubItemToken token = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(this.packedWireType, source)) { list.Add(base.Tail.Read(null, source)); } ProtoReader.EndSubItem(token, source); } else { do { list.Add(base.Tail.Read(null, source)); }while (source.TryReadFieldHeader(fieldNumber)); } int offset = this.AppendToCollection ? ((value == null) ? 0 : ((Array)value).Length) : 0; Array array = Array.CreateInstance(this.itemType, (int)(offset + list.Count)); if (offset != 0) { ((Array)value).CopyTo(array, 0); } list.CopyTo(array, offset); return(array); }
public object Read(object value, ProtoReader source) { UnityEngine.GradientAlphaKey data = (UnityEngine.GradientAlphaKey)value; int fieldNumber = 0; SubItemToken token = ProtoReader.StartSubItem(source); while ((fieldNumber = source.ReadFieldHeader()) != 0) { switch (fieldNumber) { case 1: data.time = source.ReadSingle(); break; case 2: data.alpha = source.ReadSingle(); break; default: source.SkipField(); break; } } ProtoReader.EndSubItem(token, source); return(data); }
public object Read(object value, ProtoReader source) { UnityEngine.Bounds data = (UnityEngine.Bounds)value; int fieldNumber = 0; SubItemToken token = ProtoReader.StartSubItem(source); while ((fieldNumber = source.ReadFieldHeader()) != 0) { switch (fieldNumber) { case 1: data.center = (UnityEngine.Vector3) this.vector3Serializer.Read(data.center, source); break; case 2: data.size = (UnityEngine.Vector3) this.vector3Serializer.Read(data.size, source); break; default: source.SkipField(); break; } } ProtoReader.EndSubItem(token, source); return(data); }
private void ReadCurrentRow() { int field; if (currentRow == null) { currentRow = new object[colReaders.Count]; } else { Array.Clear(currentRow, 0, currentRow.Length); } SubItemToken token = ProtoReader.StartSubItem(reader); while ((field = reader.ReadFieldHeader()) != 0) { if (field > currentRow.Length) { reader.SkipField(); } else { int i = field - 1; currentRow[i] = colReaders[i](); } } ProtoReader.EndSubItem(token, reader); }
/// <summary> /// Parses a Guid from a protobuf stream /// </summary> public static Guid ReadGuid(ProtoReader source) { ulong low = 0, high = 0; int fieldNumber; SubItemToken token = ProtoReader.StartSubItem(source); while ((fieldNumber = source.ReadFieldHeader()) > 0) { switch (fieldNumber) { case FieldGuidLow: low = source.ReadUInt64(); break; case FieldGuidHigh: high = source.ReadUInt64(); break; default: source.SkipField(); break; } } ProtoReader.EndSubItem(token, source); if (low == 0 && high == 0) { return(Guid.Empty); } uint a = (uint)(low >> 32), b = (uint)low, c = (uint)(high >> 32), d = (uint)high; return(new Guid((int)b, (short)a, (short)(a >> 16), (byte)d, (byte)(d >> 8), (byte)(d >> 16), (byte)(d >> 24), (byte)c, (byte)(c >> 8), (byte)(c >> 16), (byte)(c >> 24))); }
public override object Read(object value, ProtoReader source) { int field = source.FieldNumber; object origValue = value; if (value == null) { value = ProtobufTypeHelper.CreateInstance(concreteType); } bool isList = IsList && !SuppressIList; if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source); if (isList) { IList list = (IList)value; while (ProtoReader.HasSubValue(packedWireType, source)) { list.Add(Tail.Read(null, source)); } } else { object[] args = new object[1]; while (ProtoReader.HasSubValue(packedWireType, source)) { args[0] = Tail.Read(null, source); add.Invoke(value, args); } } ProtoReader.EndSubItem(token, source); } else { if (isList) { IList list = (IList)value; do { object item = Tail.Read(null, source); item = ProtobufTypeHelper.ConvertCLRInstance(item); list.Add(item); } while (source.TryReadFieldHeader(field)); } else { object[] args = new object[1]; do { args[0] = Tail.Read(null, source); add.Invoke(value, args); } while (source.TryReadFieldHeader(field)); } } return(origValue == value ? null : value); }
public override object Read(object value, ProtoReader source) { int field = source.FieldNumber; object obj = value; if (value == null) { value = Activator.CreateInstance(concreteType); } bool flag = IsList && !SuppressIList; if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source); if (flag) { IList list = (IList)value; while (ProtoReader.HasSubValue(packedWireType, source)) { list.Add(base.Tail.Read(null, source)); } } else { object[] array = new object[1]; while (ProtoReader.HasSubValue(packedWireType, source)) { array[0] = base.Tail.Read(null, source); add.Invoke(value, array); } } ProtoReader.EndSubItem(token, source); } else if (flag) { IList list2 = (IList)value; do { list2.Add(base.Tail.Read(null, source)); }while (source.TryReadFieldHeader(field)); } else { object[] array2 = new object[1]; do { array2[0] = base.Tail.Read(null, source); add.Invoke(value, array2); }while (source.TryReadFieldHeader(field)); } if (obj != value) { return(value); } return(null); }
public override object Read(object value, ProtoReader source) { int fieldNumber = source.FieldNumber; object obj2 = value; if (value == null) { value = Activator.CreateInstance(this.concreteType); } bool flag = this.IsList && !this.SuppressIList; if ((this.packedWireType != WireType.None) && (source.WireType == WireType.String)) { SubItemToken token = ProtoReader.StartSubItem(source); if (flag) { IList list = (IList)value; while (ProtoReader.HasSubValue(this.packedWireType, source)) { list.Add(base.Tail.Read(null, source)); } } else { object[] parameters = new object[1]; while (ProtoReader.HasSubValue(this.packedWireType, source)) { parameters[0] = base.Tail.Read(null, source); this.add.Invoke(value, parameters); } } ProtoReader.EndSubItem(token, source); } else if (flag) { IList list2 = (IList)value; do { list2.Add(base.Tail.Read(null, source)); }while (source.TryReadFieldHeader(fieldNumber)); } else { object[] objArray2 = new object[1]; do { objArray2[0] = base.Tail.Read(null, source); this.add.Invoke(value, objArray2); }while (source.TryReadFieldHeader(fieldNumber)); } if (obj2 != value) { return(value); } return(null); }
public override object Read(object value, ProtoReader source) { int fieldNumber = source.FieldNumber; object obj = value; if (value == null) { value = Activator.CreateInstance(this.concreteType); } bool flag = (!this.IsList ? false : !this.SuppressIList); if (this.packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken subItemToken = ProtoReader.StartSubItem(source); if (!flag) { object[] objArray = new object[1]; while (ProtoReader.HasSubValue(this.packedWireType, source)) { objArray[0] = this.Tail.Read(null, source); [email protected](value, objArray); } } else { IList lists = (IList)value; while (ProtoReader.HasSubValue(this.packedWireType, source)) { lists.Add(this.Tail.Read(null, source)); } } ProtoReader.EndSubItem(subItemToken, source); } else if (!flag) { object[] objArray1 = new object[1]; do { objArray1[0] = this.Tail.Read(null, source); [email protected](value, objArray1); }while (source.TryReadFieldHeader(fieldNumber)); } else { IList lists1 = (IList)value; do { lists1.Add(this.Tail.Read(null, source)); }while (source.TryReadFieldHeader(fieldNumber)); } if (obj != value) { return(value); } return(null); }
private void ReadResult() { this.currentResultToken = ProtoReader.StartSubItem(this.protoReader); this.ReadColumns(); this.ReadFieldHeader(FieldHeaders.Records); this.currentRecordsToken = ProtoReader.StartSubItem(this.protoReader); }
// Token: 0x06003575 RID: 13685 RVA: 0x001348B0 File Offset: 0x00132CB0 public override object Read(object value, ProtoReader source) { object obj = builderFactory.Invoke(null, null); int fieldNumber = source.FieldNumber; object[] array = new object[1]; if (base.AppendToCollection && value != null && ((IList)value).Count != 0) { if (addRange != null) { array[0] = value; addRange.Invoke(obj, array); } else { IEnumerator enumerator = ((IList)value).GetEnumerator(); try { while (enumerator.MoveNext()) { object obj2 = enumerator.Current; array[0] = obj2; add.Invoke(obj, array); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } } } if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(packedWireType, source)) { array[0] = Tail.Read(null, source); add.Invoke(obj, array); } ProtoReader.EndSubItem(token, source); } else { do { array[0] = Tail.Read(null, source); add.Invoke(obj, array); }while (source.TryReadFieldHeader(fieldNumber)); } return(finish.Invoke(obj, null)); }
public object Deserialize(object obj, ProtoReader reader, ProtobufSerializerPrecompiled model) { var scale = obj as ScaleFixer; reader.ReadFieldHeader(); var token = ProtoReader.StartSubItem(reader); scale.scale = (Vector3)AlternativeSerializer.PrecompDeserialize(model, AlternativeSerializer.PrecompGetKey(model, typeof(Vector3)), scale.scale, reader); ProtoReader.EndSubItem(token, reader); return(scale); }
public override object Read(object value, ProtoReader source) { int field = source.FieldNumber; if (value == null) { value = Activator.CreateInstance(concreteType); } if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source); if (isList) { IList list = (IList)value; while (ProtoReader.HasSubValue(packedWireType, source)) { list.Add(Tail.Read(null, source)); } } else { object[] args = new object[1]; while (ProtoReader.HasSubValue(packedWireType, source)) { args[0] = Tail.Read(null, source); add.Invoke(value, args); } } ProtoReader.EndSubItem(token, source); } else { if (isList) { IList list = (IList)value; do { list.Add(Tail.Read(null, source)); } while (source.TryReadFieldHeader(field)); } else { object[] args = new object[1]; do { args[0] = Tail.Read(null, source); add.Invoke(value, args); } while (source.TryReadFieldHeader(field)); } } return(value); }
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); }
private void ReadColumn(int ordinal) { var columnToken = ProtoReader.StartSubItem(this.protoReader); var name = this.ReadColumnName(); var protoBufDataType = this.ReadColumnType(); var column = new ProtoBufDataColumn(name: name, ordinal: ordinal, dataType: TypeHelper.GetType(protoBufDataType), protoBufDataType: protoBufDataType); this.columns.Add(column); this.protoReader.ReadFieldHeader(); ProtoReader.EndSubItem(columnToken, this.protoReader); }
private static int ReadRowId(ProtoReader reader) { var token = ProtoReader.StartSubItem(reader); var fieldId = reader.ReadFieldHeader(); if (fieldId != ProtobufFieldIds.RowId) { return(-1); } var rowId = reader.ReadInt32(); var dummyFieldId = reader.ReadFieldHeader(); ProtoReader.EndSubItem(token, reader); return(rowId); }
public object Read(object value, ProtoReader source) { UnityEngine.Gradient data = (UnityEngine.Gradient)(value == null ? CreateInstance(source) : value); int fieldNumber = 0; SubItemToken token = ProtoReader.StartSubItem(source); while ((fieldNumber = source.ReadFieldHeader()) != 0) { switch (fieldNumber) { case 1: data.mode = (UnityEngine.GradientMode)source.ReadInt32(); break; case 2: alphaKeys.Clear(); do { alphaKeys.Add((UnityEngine.GradientAlphaKey) this.alphaKeySerializer.Read( new UnityEngine.GradientAlphaKey(), source)); } while (source.TryReadFieldHeader(2)); data.alphaKeys = alphaKeys.ToArray(); break; case 3: colorKeys.Clear(); do { colorKeys.Add((UnityEngine.GradientColorKey) this.colorKeySerializer.Read( new UnityEngine.GradientColorKey(), source)); } while (source.TryReadFieldHeader(3)); data.colorKeys = colorKeys.ToArray(); break; default: source.SkipField(); break; } } ProtoReader.EndSubItem(token, source); return(data); }
public override object Read(ProtoReader source, ref ProtoReader.State state, object value) { object builderInstance = builderFactory.Invoke(null, null); int field = source.FieldNumber; object[] args = new object[1]; if (AppendToCollection && value != null && (isEmpty != null ? !(bool)isEmpty.GetValue(value, null) : (int)length.GetValue(value, null) != 0)) { if (addRange != null) { args[0] = value; addRange.Invoke(builderInstance, args); } else { foreach (object item in (ICollection)value) { args[0] = item; add.Invoke(builderInstance, args); } } } if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source, ref state); while (ProtoReader.HasSubValue(packedWireType, source)) { args[0] = Tail.Read(source, ref state, null); add.Invoke(builderInstance, args); } ProtoReader.EndSubItem(token, source, ref state); } else { do { args[0] = Tail.Read(source, ref state, null); add.Invoke(builderInstance, args); } while (source.TryReadFieldHeader(ref state, field)); } return(finish.Invoke(builderInstance, null)); }
public object Read(object value, ProtoReader source) { object[] values = new object[_members.Length]; bool invokeCtor = false; int reservedTrap = -1; if (value == null) { reservedTrap = ProtoReader.ReserveNoteObject(source); invokeCtor = true; } var token = ProtoReader.StartSubItem(source); for (int i = 0; i < values.Length; i++) { values[i] = GetValue(value, i); } int field; while ((field = source.ReadFieldHeader()) > 0) { invokeCtor = true; if (field <= _tails.Length) { IProtoSerializer tail = _tails[field - 1]; values[field - 1] = _tails[field - 1].Read(tail.RequiresOldValue ? values[field - 1] : null, source); } else { source.SkipField(); } } ProtoReader.EndSubItem(token, source); if (invokeCtor) { var r = _ctor.Invoke(values); // inside references won't work, but from outside will // this is a common problem when deserializing immutable types ProtoReader.NoteReservedTrappedObject(reservedTrap, r, source); return(r); } return(value); }
// Token: 0x060035AC RID: 13740 RVA: 0x00134CD4 File Offset: 0x001330D4 public override object Read(object value, ProtoReader source) { SubItemToken token = ProtoReader.StartSubItem(source); int num; while ((num = source.ReadFieldHeader()) > 0) { if (num == 1) { value = Tail.Read(value, source); } else { source.SkipField(); } } ProtoReader.EndSubItem(token, source); return(value); }
public override object Read(ProtoReader source, ref ProtoReader.State state, object value) { SubItemToken tok = ProtoReader.StartSubItem(source, ref state); int field; while ((field = source.ReadFieldHeader(ref state)) > 0) { if (field == Tag) { value = Tail.Read(source, ref state, value); } else { source.SkipField(ref state); } } ProtoReader.EndSubItem(tok, source, ref state); return(value); }
MetaType TryRead(MetaType metaType, ProtoReader source, int recursionLevel) { SubType[] subTypes = metaType.GetSubtypes(); int fieldNumber; SubType subType; if (recursionLevel == 0) { if (source.WireType != WireType.String) { fieldNumber = source.ReadInt32() - 1; subType = subTypes.FirstOrDefault(st => st.FieldNumber == fieldNumber); return(subType?.DerivedType ?? metaType); // versioning } } SubItemToken?token = null; if (recursionLevel == 0) { token = ProtoReader.StartSubItem(source); } try { if (!ProtoReader.HasSubValue(WireType.Variant, source)) { return(metaType); } fieldNumber = source.ReadInt32() - 1; subType = subTypes.FirstOrDefault(st => st.FieldNumber == fieldNumber); return(subType != null // versioning ? TryRead(subType.DerivedType, source, recursionLevel + 1) : metaType); } finally { if (token != null) { ProtoReader.EndSubItem(token.Value, true, source); } } }
private void ReadRecord() { if (this.buffers == null) { this.buffers = new ProtoBufDataBuffer[this.columns.Count]; ProtoBufDataBuffer.Initialize(this.buffers); } else { ProtoBufDataBuffer.Clear(this.buffers); } var recordToken = ProtoReader.StartSubItem(this.protoReader); this.ReadRecordValues(); ProtoReader.EndSubItem(recordToken, this.protoReader); }