/// <summary> /// Reads an unknown field, either parsing it and storing it or skipping it. /// </summary> /// <remarks> /// If the current set of options is empty and we manage to read a field, a new set of options /// will be created and returned. Otherwise, the return value is <c>this</c>. This allows /// us to start with a singleton empty set of options and just create new ones where necessary. /// </remarks> /// <param name="input">Input stream to read from. </param> /// <returns>The resulting set of custom options, either <c>this</c> or a new set.</returns> internal CustomOptions ReadOrSkipUnknownField(CodedInputStream input) { var tag = input.LastTag; var field = WireFormat.GetTagFieldNumber(tag); switch (WireFormat.GetTagWireType(tag)) { case WireFormat.WireType.LengthDelimited: return(AddValue(field, new FieldValue(input.ReadBytes()))); case WireFormat.WireType.Fixed32: return(AddValue(field, new FieldValue(input.ReadFixed32()))); case WireFormat.WireType.Fixed64: return(AddValue(field, new FieldValue(input.ReadFixed64()))); case WireFormat.WireType.Varint: return(AddValue(field, new FieldValue(input.ReadRawVarint64()))); // For StartGroup, EndGroup or any wire format we don't understand, // just use the normal behavior (call SkipLastField). default: input.SkipLastField(); return(this); } }
public void AddEntriesFrom(CodedInputStream input, FieldCodec <T> codec) { // TODO: Inline some of the Add code, so we can avoid checking the size on every // iteration and the mutability. uint tag = input.LastTag; var reader = codec.ValueReader; // Value types can be packed or not. if (typeof(T).IsValueType() && WireFormat.GetTagWireType(tag) == WireFormat.WireType.LengthDelimited) { int length = input.ReadLength(); if (length > 0) { int oldLimit = input.PushLimit(length); while (!input.ReachedLimit) { Add(reader(input)); } input.PopLimit(oldLimit); } // Empty packed field. Odd, but valid - just ignore. } else { // Not packed... (possibly not packable) do { Add(reader(input)); } while (input.MaybeConsumeTag(tag)); } }
private List <Address> GetRelatedAccount(Transaction transaction) { //var hashes = ECParameters.Parser.ParseFrom(transaction.Params).Params.Select(p => p.HashVal); List <Address> addresses = new List <Address>(); using (MemoryStream mm = new MemoryStream(transaction.Params.ToByteArray())) using (CodedInputStream input = new CodedInputStream(mm)) { uint tag; while ((tag = input.ReadTag()) != 0) { switch (WireFormat.GetTagWireType(tag)) { case WireFormat.WireType.Varint: input.ReadUInt64(); break; case WireFormat.WireType.LengthDelimited: var bytes = input.ReadBytes(); if (bytes.Length == 18 + 2) // todo what leength should this be ? { // TODO: Ignore if parsing failed, which means our guess is wrong - the bytes is not an address var h = new Address(); h.MergeFrom(bytes); addresses.Add(h); } break; } } } addresses.Add(transaction.From); return(addresses); }
public int CalculateSize(FieldCodec <T> codec) { if (count == 0) { return(0); } uint tag = codec.Tag; if (typeof(T).IsValueType() && WireFormat.GetTagWireType(tag) == WireFormat.WireType.LengthDelimited) { int dataSize = CalculatePackedDataSize(codec); return(CodedOutputStream.ComputeRawVarint32Size(tag) + CodedOutputStream.ComputeLengthSize(dataSize) + dataSize); } else { var sizeCalculator = codec.ValueSizeCalculator; int size = count * CodedOutputStream.ComputeRawVarint32Size(tag); for (int i = 0; i < count; i++) { size += sizeCalculator(array[i]); } return(size); } }
public void WriteTo(CodedOutputStream output, FieldCodec <T> codec) { if (count == 0) { return; } var writer = codec.ValueWriter; var tag = codec.Tag; if (typeof(T).IsValueType() && WireFormat.GetTagWireType(tag) == WireFormat.WireType.LengthDelimited) { // Packed primitive type uint size = (uint)CalculatePackedDataSize(codec); output.WriteTag(tag); output.WriteRawVarint32(size); for (int i = 0; i < count; i++) { writer(output, array[i]); } } else { // Not packed: a simple tag/value pair for each value. // Can't use codec.WriteTagAndValue, as that omits default values. for (int i = 0; i < count; i++) { output.WriteTag(tag); writer(output, array[i]); } } }
public async Task <IEnumerable <string> > GetResources(Transaction transaction) { //var hashes = ECParameters.Parser.ParseFrom(transaction.Params).Params.Select(p => p.HashVal); List <Address> addresses = new List <Address>(); using (MemoryStream mm = new MemoryStream(transaction.Params.ToByteArray())) using (CodedInputStream input = new CodedInputStream(mm)) { uint tag; while ((tag = input.ReadTag()) != 0) { switch (WireFormat.GetTagWireType(tag)) { case WireFormat.WireType.Varint: input.ReadUInt64(); break; case WireFormat.WireType.LengthDelimited: var bytes = input.ReadBytes(); if (bytes.Length == 18 + 2) // todo what leength should this be ? { var h = new Address(); h.MergeFrom(bytes); addresses.Add(h); } break; } } } addresses.Add(transaction.From); return(await Task.FromResult(addresses.Select(a => a.GetFormatted()))); }
public static uint ReadProtoInt(byte[] buffer, int tags) { uint tag = 0; string fieldName = ""; CodedInputStream input = CodedInputStream.CreateInstance(buffer); while (input.ReadTag(out tag, out fieldName)) { int Field = WireFormat.GetTagFieldNumber(tag); WireFormat.WireType WireType = WireFormat.GetTagWireType(tag); switch (WireType) { case WireFormat.WireType.LengthDelimited: ByteString tmps = ByteString.Empty; input.ReadBytes(ref tmps); break; case WireFormat.WireType.Fixed32: break; case WireFormat.WireType.Fixed64: break; case WireFormat.WireType.Varint: uint val = 0; input.ReadUInt32(ref val); if (tags == tag >> 3) { return(val); } break; } } return(0); }
public async Task <IEnumerable <string> > GetResources(Hash chainId, Transaction transaction) { //var hashes = ECParameters.Parser.ParseFrom(transaction.Params).Params.Select(p => p.HashVal); List <Address> hashes = new List <Address>(); using (MemoryStream mm = new MemoryStream(transaction.Params.ToByteArray())) using (CodedInputStream input = new CodedInputStream(mm)) { uint tag; while ((tag = input.ReadTag()) != 0) { switch (WireFormat.GetTagWireType(tag)) { case WireFormat.WireType.Varint: input.ReadUInt64(); break; case WireFormat.WireType.LengthDelimited: var bytes = input.ReadBytes(); // Address used to be 32 bytes long and was reduced to 18 // accept both so that we don't have to fix tests if (bytes.Length == 34 || bytes.Length == 20) { var h = new Address(); ((IMessage)h).MergeFrom(bytes); hashes.Add(h); } break; } } } hashes.Add(transaction.From); return(await Task.FromResult(hashes.Select(a => a.DumpHex()).ToList())); }
public static void ReadProtoRawDataS(List <object> list, byte[] buffer, int tags) { uint tag = 0; string fieldName = ""; CodedInputStream input = CodedInputStream.CreateInstance(buffer); while (input.ReadTag(out tag, out fieldName)) { int Field = WireFormat.GetTagFieldNumber(tag); WireFormat.WireType WireType = WireFormat.GetTagWireType(tag); switch (WireType) { case WireFormat.WireType.LengthDelimited: ByteString tmps = ByteString.Empty; input.ReadBytes(ref tmps); if (tags == tag >> 3) { //return tmps.ToByteArray(); list.Add(tmps.ToByteArray()); } break; case WireFormat.WireType.Fixed32: break; case WireFormat.WireType.Fixed64: break; case WireFormat.WireType.Varint: int val = 0; input.ReadInt32(ref val); break; } } }
public void WriteTo(CodedOutputStream output, FieldCodec <T> codec) { if (this.count == 0) { goto IL_0B; } goto IL_1E1; uint arg_18F_0; Action <CodedOutputStream, T> valueWriter; while (true) { IL_18A: uint num; switch ((num = (arg_18F_0 ^ 1953686162u)) % 17u) { case 0u: arg_18F_0 = (num * 3203489594u ^ 1031590236u); continue; case 1u: { uint tag; output.WriteTag(tag); uint value; output.WriteRawVarint32(value); int num2 = 0; arg_18F_0 = (num * 515923323u ^ 23271688u); continue; } case 2u: { uint tag = codec.Tag; arg_18F_0 = ((RepeatedField <T> .smethod_1(typeof(T).TypeHandle).IsValueType() ? 1056524744u : 1802064101u) ^ num * 3884348354u); continue; } case 3u: arg_18F_0 = (num * 2769258316u ^ 2862122040u); continue; case 4u: { uint value = (uint)this.CalculatePackedDataSize(codec); arg_18F_0 = (num * 4231138135u ^ 3155140988u); continue; } case 5u: { uint tag; output.WriteTag(tag); int num3; valueWriter(output, this.array[num3]); num3++; arg_18F_0 = 603286320u; continue; } case 6u: { int num2; arg_18F_0 = ((num2 < this.count) ? 1868080555u : 798875600u); continue; } case 8u: { uint tag; arg_18F_0 = (((WireFormat.GetTagWireType(tag) != WireFormat.WireType.LengthDelimited) ? 457279799u : 500871248u) ^ num * 3734816805u); continue; } case 9u: { int num3 = 0; arg_18F_0 = 1317493604u; continue; } case 10u: { int num2; valueWriter(output, this.array[num2]); arg_18F_0 = 1207070914u; continue; } case 11u: { int num3; arg_18F_0 = ((num3 >= this.count) ? 1230221189u : 414117966u); continue; } case 12u: goto IL_1E1; case 13u: return; case 14u: { int num2; num2++; arg_18F_0 = (num * 2746311965u ^ 3912762196u); continue; } case 15u: return; case 16u: goto IL_0B; } break; } return; IL_0B: arg_18F_0 = 793007137u; goto IL_18A; IL_1E1: valueWriter = codec.ValueWriter; arg_18F_0 = 158090120u; goto IL_18A; }
public int CalculateSize(FieldCodec <T> codec) { if (this.count == 0) { goto IL_7F; } goto IL_14C; uint arg_10E_0; int num2; uint tag; int num3; while (true) { IL_109: uint num; switch ((num = (arg_10E_0 ^ 4001631253u)) % 12u) { case 0u: goto IL_15A; case 1u: num2 = this.CalculatePackedDataSize(codec); arg_10E_0 = (num * 3891558231u ^ 1575501722u); continue; case 2u: goto IL_14C; case 3u: { Func <T, int> valueSizeCalculator = codec.ValueSizeCalculator; num3 = this.count * CodedOutputStream.ComputeRawVarint32Size(tag); arg_10E_0 = 3044489711u; continue; } case 4u: { Func <T, int> valueSizeCalculator; int num4; num3 += valueSizeCalculator(this.array[num4]); num4++; arg_10E_0 = 2737623098u; continue; } case 5u: return(0); case 6u: arg_10E_0 = (((WireFormat.GetTagWireType(tag) == WireFormat.WireType.LengthDelimited) ? 1110063554u : 216719364u) ^ num * 1888421937u); continue; case 7u: goto IL_7F; case 8u: arg_10E_0 = ((RepeatedField <T> .smethod_1(typeof(T).TypeHandle).IsValueType() ? 405727823u : 968969150u) ^ num * 1456731362u); continue; case 10u: { int num4 = 0; arg_10E_0 = (num * 2246578605u ^ 3048063944u); continue; } case 11u: { int num4; arg_10E_0 = ((num4 < this.count) ? 3082958981u : 4069993376u); continue; } } break; } return(num3); IL_15A: return(CodedOutputStream.ComputeRawVarint32Size(tag) + CodedOutputStream.ComputeLengthSize(num2) + num2); IL_7F: arg_10E_0 = 2713212068u; goto IL_109; IL_14C: tag = codec.Tag; arg_10E_0 = 2759193717u; goto IL_109; }
public void AddEntriesFrom(CodedInputStream input, FieldCodec <T> codec) { uint lastTag = input.LastTag; Func <CodedInputStream, T> valueReader = codec.ValueReader; if (RepeatedField <T> .smethod_1(typeof(T).TypeHandle).IsValueType()) { goto IL_79; } goto IL_189; uint arg_147_0; while (true) { IL_142: uint num; switch ((num = (arg_147_0 ^ 349581016u)) % 13u) { case 0u: arg_147_0 = ((input.MaybeConsumeTag(lastTag) ? 2792542167u : 2493560502u) ^ num * 4283985340u); continue; case 1u: arg_147_0 = (((WireFormat.GetTagWireType(lastTag) == WireFormat.WireType.LengthDelimited) ? 4182580420u : 2445968179u) ^ num * 3573087188u); continue; case 2u: arg_147_0 = (num * 2407926176u ^ 627495612u); continue; case 3u: { int num2; arg_147_0 = (((num2 > 0) ? 704969730u : 1347903514u) ^ num * 2106852334u); continue; } case 4u: { int oldLimit; input.PopLimit(oldLimit); arg_147_0 = (num * 2913868755u ^ 1655185686u); continue; } case 6u: { int num2; int oldLimit = input.PushLimit(num2); arg_147_0 = (num * 3972840873u ^ 320789690u); continue; } case 7u: goto IL_79; case 8u: this.Add(valueReader(input)); arg_147_0 = 1293084732u; continue; case 9u: arg_147_0 = ((!input.ReachedLimit) ? 862879642u : 1176527045u); continue; case 10u: return; case 11u: goto IL_189; case 12u: { int num2 = input.ReadLength(); arg_147_0 = (num * 1888486294u ^ 430467554u); continue; } } break; } return; IL_79: arg_147_0 = 431838837u; goto IL_142; IL_189: this.Add(valueReader(input)); arg_147_0 = 320588544u; goto IL_142; }