private static void ValidateSymbolName(IDescriptor descriptor) { if (!DescriptorPool.smethod_7(descriptor.Name, "")) { goto IL_55; } IL_21: int arg_2B_0 = 164232957; IL_26: switch ((arg_2B_0 ^ 1498968607) % 5) { case 1: throw new DescriptorValidationException(descriptor, Module.smethod_35 <string>(3327537739u)); case 2: IL_55: arg_2B_0 = (DescriptorPool.smethod_8(DescriptorPool.ValidationRegex, descriptor.Name) ? 956386433 : 1225429300); goto IL_26; case 3: throw new DescriptorValidationException(descriptor, DescriptorPool.smethod_6(Module.smethod_33 <string>(3031927268u), descriptor.Name, Module.smethod_37 <string>(1895443896u))); case 4: goto IL_21; } }
/// <summary> /// Builds a FileDescriptor from its protocol buffer representation. /// </summary> /// <param name="descriptorData">The original serialized descriptor data. /// We have only limited proto2 support, so serializing FileDescriptorProto /// would not necessarily give us this.</param> /// <param name="proto">The protocol message form of the FileDescriptor.</param> /// <param name="dependencies">FileDescriptors corresponding to all of the /// file's dependencies, in the exact order listed in the .proto file. May be null, /// in which case it is treated as an empty array.</param> /// <param name="allowUnknownDependencies">Whether unknown dependencies are ignored (true) or cause an exception to be thrown (false).</param> /// <param name="generatedCodeInfo">Details about generated code, for the purposes of reflection.</param> /// <exception cref="DescriptorValidationException">If <paramref name="proto"/> is not /// a valid descriptor. This can occur for a number of reasons, such as a field /// having an undefined type or because two messages were defined with the same name.</exception> private static FileDescriptor BuildFrom(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo) { // Building descriptors involves two steps: translating and linking. // In the translation step (implemented by FileDescriptor's // constructor), we build an object tree mirroring the // FileDescriptorProto's tree and put all of the descriptors into the // DescriptorPool's lookup tables. In the linking step, we look up all // type references in the DescriptorPool, so that, for example, a // FieldDescriptor for an embedded message contains a pointer directly // to the Descriptor for that message's type. We also detect undefined // types in the linking step. if (dependencies == null) { dependencies = new FileDescriptor[0]; } DescriptorPool pool = new DescriptorPool(dependencies); FileDescriptor result = new FileDescriptor(descriptorData, proto, dependencies, pool, allowUnknownDependencies, generatedCodeInfo); // Validate that the dependencies we've been passed (as FileDescriptors) are actually the ones we // need. if (dependencies.Length != proto.Dependency.Count) { throw new DescriptorValidationException( result, "Dependencies passed to FileDescriptor.BuildFrom() don't match " + "those listed in the FileDescriptorProto."); } result.CrossLink(); return(result); }
private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, IEnumerable <FileDescriptor> dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo) { SerializedData = descriptorData; DescriptorPool = pool; Proto = proto; Dependencies = new ReadOnlyCollection <FileDescriptor>(dependencies.ToList()); PublicDependencies = DeterminePublicDependencies(this, proto, dependencies, allowUnknownDependencies); pool.AddPackage(Package, this); MessageTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.MessageType, (message, index) => new MessageDescriptor(message, this, null, index, generatedCodeInfo?.NestedTypes[index])); EnumTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.EnumType, (enumType, index) => new EnumDescriptor(enumType, this, null, index, generatedCodeInfo?.NestedEnums[index])); Services = DescriptorUtil.ConvertAndMakeReadOnly(proto.Service, (service, index) => new ServiceDescriptor(service, this, index)); declarations = new Lazy <Dictionary <IDescriptor, DescriptorDeclaration> >(CreateDeclarationMap, LazyThreadSafetyMode.ExecutionAndPublication); }
/// <summary> /// Converts the given descriptor binary data into FileDescriptor objects. /// Note: reflection using the returned FileDescriptors is not currently supported. /// </summary> /// <param name="descriptorData">The binary file descriptor proto data. Must not be null, and any /// dependencies must come before the descriptor which depends on them. (If A depends on B, and B /// depends on C, then the descriptors must be presented in the order C, B, A.) This is compatible /// with the order in which protoc provides descriptors to plugins.</param> /// <returns>The file descriptors corresponding to <paramref name="descriptorData"/>.</returns> public static IReadOnlyList <FileDescriptor> BuildFromByteStrings(IEnumerable <ByteString> descriptorData) { ProtoPreconditions.CheckNotNull(descriptorData, nameof(descriptorData)); // TODO: See if we can build a single DescriptorPool instead of building lots of them. // This will all behave correctly, but it's less efficient than we'd like. var descriptors = new List <FileDescriptor>(); var descriptorsByName = new Dictionary <string, FileDescriptor>(); foreach (var data in descriptorData) { var proto = FileDescriptorProto.Parser.ParseFrom(data); var dependencies = new List <FileDescriptor>(); foreach (var dependencyName in proto.Dependency) { if (!descriptorsByName.TryGetValue(dependencyName, out var dependency)) { throw new ArgumentException($"Dependency missing: {dependencyName}"); } dependencies.Add(dependency); } var pool = new DescriptorPool(dependencies); FileDescriptor descriptor = new FileDescriptor( data, proto, dependencies, pool, allowUnknownDependencies: false, generatedCodeInfo: null); descriptors.Add(descriptor); if (descriptorsByName.ContainsKey(descriptor.Name)) { throw new ArgumentException($"Duplicate descriptor name: {descriptor.Name}"); } descriptorsByName.Add(descriptor.Name, descriptor); } return(new ReadOnlyCollection <FileDescriptor>(descriptors)); }
internal void AddFieldByNumber(FieldDescriptor field) { DescriptorPool.DescriptorIntPair key = new DescriptorPool.DescriptorIntPair(field.ContainingType, field.FieldNumber); FieldDescriptor fieldDescriptor; if (this.fieldsByNumber.TryGetValue(key, out fieldDescriptor)) { throw new DescriptorValidationException(field, DescriptorPool.smethod_9(new object[] { Module.smethod_36 <string>(896911572u), field.FieldNumber, Module.smethod_35 <string>(1732735873u), field.ContainingType.FullName, Module.smethod_34 <string>(3822284802u), fieldDescriptor.Name, Module.smethod_37 <string>(3940659401u) })); } this.fieldsByNumber[key] = field; }
/// <summary> /// Builds a FileDescriptor from its protocol buffer representation. /// </summary> /// <param name="descriptorData">The original serialized descriptor data. /// We have only limited proto2 support, so serializing FileDescriptorProto /// would not necessarily give us this.</param> /// <param name="proto">The protocol message form of the FileDescriptor.</param> /// <param name="dependencies">FileDescriptors corresponding to all of the /// file's dependencies, in the exact order listed in the .proto file. May be null, /// in which case it is treated as an empty array.</param> /// <param name="allowUnknownDependencies">Whether unknown dependencies are ignored (true) or cause an exception to be thrown (false).</param> /// <param name="generatedCodeInfo">Reflection information, if any. May be null, specifically for non-generated code.</param> /// <exception cref="DescriptorValidationException">If <paramref name="proto"/> is not /// a valid descriptor. This can occur for a number of reasons, such as a field /// having an undefined type or because two messages were defined with the same name.</exception> private static FileDescriptor BuildFrom(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, bool allowUnknownDependencies, GeneratedCodeInfo generatedCodeInfo) { // Building descriptors involves two steps: translating and linking. // In the translation step (implemented by FileDescriptor's // constructor), we build an object tree mirroring the // FileDescriptorProto's tree and put all of the descriptors into the // DescriptorPool's lookup tables. In the linking step, we look up all // type references in the DescriptorPool, so that, for example, a // FieldDescriptor for an embedded message contains a pointer directly // to the Descriptor for that message's type. We also detect undefined // types in the linking step. if (dependencies == null) { dependencies = new FileDescriptor[0]; } DescriptorPool pool = new DescriptorPool(dependencies); FileDescriptor result = new FileDescriptor(descriptorData, proto, dependencies, pool, allowUnknownDependencies, generatedCodeInfo); // TODO(jonskeet): Reinstate these checks, or get rid of them entirely. They aren't in the Java code, // and fail for the CustomOptions test right now. (We get "descriptor.proto" vs "google/protobuf/descriptor.proto".) //if (dependencies.Length != proto.DependencyCount) //{ // throw new DescriptorValidationException(result, // "Dependencies passed to FileDescriptor.BuildFrom() don't match " + // "those listed in the FileDescriptorProto."); //} //for (int i = 0; i < proto.DependencyCount; i++) //{ // if (dependencies[i].Name != proto.DependencyList[i]) // { // throw new DescriptorValidationException(result, // "Dependencies passed to FileDescriptor.BuildFrom() don't match " + // "those listed in the FileDescriptorProto."); // } //} result.CrossLink(); return(result); }
private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedCodeInfo generatedCodeInfo) { this.descriptorData = descriptorData; this.pool = pool; this.proto = proto; this.dependencies = new ReadOnlyCollection <FileDescriptor>((FileDescriptor[])dependencies.Clone()); publicDependencies = DeterminePublicDependencies(this, proto, dependencies, allowUnknownDependencies); pool.AddPackage(Package, this); messageTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.MessageType, (message, index) => new MessageDescriptor(message, this, null, index, generatedCodeInfo == null ? null : generatedCodeInfo.NestedTypes[index])); enumTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.EnumType, (enumType, index) => new EnumDescriptor(enumType, this, null, index, generatedCodeInfo == null ? null : generatedCodeInfo.NestedEnums[index])); services = DescriptorUtil.ConvertAndMakeReadOnly(proto.Service, (service, index) => new ServiceDescriptor(service, this, index)); }
internal IDescriptor LookupSymbol(string name, IDescriptor relativeTo) { if (DescriptorPool.smethod_10(name, Module.smethod_37 <string>(3886401134u))) { goto IL_1E0; } goto IL_25F; uint arg_1EA_0; IDescriptor descriptor; int num2; string string_; while (true) { IL_1E5: uint num; switch ((num = (arg_1EA_0 ^ 1120319073u)) % 20u) { case 0u: goto IL_1E0; case 1u: arg_1EA_0 = ((descriptor == null) ? 870869395u : 499394510u); continue; case 2u: goto IL_248; case 3u: arg_1EA_0 = (num * 3182389240u ^ 2661154485u); continue; case 4u: arg_1EA_0 = (((num2 != -1) ? 1585465210u : 655580376u) ^ num * 49592841u); continue; case 5u: descriptor = this.FindSymbol <IDescriptor>(DescriptorPool.smethod_4(name, 1)); arg_1EA_0 = (num * 3672446899u ^ 3969592099u); continue; case 6u: { StringBuilder stringBuilder; descriptor = this.FindSymbol <IDescriptor>(DescriptorPool.smethod_13(stringBuilder)); arg_1EA_0 = (((descriptor != null) ? 64710281u : 267317740u) ^ num * 1678552982u); continue; } case 8u: { StringBuilder stringBuilder; int num3 = DescriptorPool.smethod_14(DescriptorPool.smethod_13(stringBuilder), Module.smethod_37 <string>(3886401134u)); arg_1EA_0 = 2002560569u; continue; } case 9u: { StringBuilder stringBuilder = DescriptorPool.smethod_12(relativeTo.FullName); arg_1EA_0 = (num * 3531444233u ^ 3381061816u); continue; } case 10u: { StringBuilder stringBuilder; DescriptorPool.smethod_16(stringBuilder, name); arg_1EA_0 = (num * 817521685u ^ 2631391113u); continue; } case 11u: arg_1EA_0 = (num * 552099699u ^ 2537391261u); continue; case 12u: { StringBuilder stringBuilder; int num3; DescriptorPool.smethod_15(stringBuilder, num3 + 1); DescriptorPool.smethod_16(stringBuilder, string_); arg_1EA_0 = 1012720395u; continue; } case 13u: descriptor = this.FindSymbol <IDescriptor>(name); arg_1EA_0 = (num * 2889115466u ^ 2648762352u); continue; case 14u: goto IL_271; case 15u: goto IL_25F; case 16u: { int num3; arg_1EA_0 = (((num3 == -1) ? 4120049240u : 3230677641u) ^ num * 813323212u); continue; } case 17u: { StringBuilder stringBuilder; int num3; DescriptorPool.smethod_15(stringBuilder, num3); arg_1EA_0 = 782561782u; continue; } case 18u: { StringBuilder stringBuilder; descriptor = this.FindSymbol <IDescriptor>(DescriptorPool.smethod_13(stringBuilder)); arg_1EA_0 = (num * 2911074500u ^ 582846468u); continue; } case 19u: { StringBuilder stringBuilder; int num3; DescriptorPool.smethod_15(stringBuilder, num3 + 1); arg_1EA_0 = (num * 3586444226u ^ 2060538829u); continue; } } break; } return(descriptor); IL_248: string arg_250_0 = DescriptorPool.smethod_3(name, 0, num2); goto IL_250; IL_271: throw new DescriptorValidationException(relativeTo, DescriptorPool.smethod_6(Module.smethod_36 <string>(1708679815u), name, Module.smethod_35 <string>(165853341u))); IL_1E0: arg_1EA_0 = 1226689332u; goto IL_1E5; IL_250: string_ = arg_250_0; arg_1EA_0 = 1911610428u; goto IL_1E5; IL_25F: num2 = DescriptorPool.smethod_11(name, '.'); if (num2 != -1) { arg_1EA_0 = 604030619u; goto IL_1E5; } arg_250_0 = name; goto IL_250; }
internal void AddSymbol(IDescriptor descriptor) { DescriptorPool.ValidateSymbolName(descriptor); string description; while (true) { IL_220: uint arg_1DA_0 = 1985145293u; while (true) { uint num; switch ((num = (arg_1DA_0 ^ 2053731764u)) % 14u) { case 0u: { string fullName; int num2; description = DescriptorPool.smethod_5(new string[] { Module.smethod_36 <string>(1708679815u), DescriptorPool.smethod_4(fullName, num2 + 1), Module.smethod_37 <string>(2801180086u), DescriptorPool.smethod_3(fullName, 0, num2), Module.smethod_35 <string>(2292255829u) }); arg_1DA_0 = 1833202264u; continue; } case 1u: { IDescriptor descriptor2; arg_1DA_0 = (((descriptor.File != descriptor2.File) ? 461553329u : 98503376u) ^ num * 1094856435u); continue; } case 2u: { string fullName; IDescriptor descriptor2; description = DescriptorPool.smethod_5(new string[] { Module.smethod_36 <string>(1708679815u), fullName, Module.smethod_35 <string>(2935817106u), descriptor2.File.Name, Module.smethod_34 <string>(4290967862u) }); arg_1DA_0 = 399949226u; continue; } case 4u: arg_1DA_0 = (num * 512943130u ^ 3276706322u); continue; case 5u: { string fullName; IDescriptor descriptor2; arg_1DA_0 = ((this.descriptorsByName.TryGetValue(fullName, out descriptor2) ? 724224651u : 816491605u) ^ num * 3835365548u); continue; } case 6u: arg_1DA_0 = (num * 587877992u ^ 2721817162u); continue; case 7u: { string fullName = descriptor.FullName; arg_1DA_0 = (num * 3042641918u ^ 2879375567u); continue; } case 8u: { string fullName; description = DescriptorPool.smethod_6(Module.smethod_33 <string>(3031927268u), fullName, Module.smethod_36 <string>(4135403163u)); arg_1DA_0 = (num * 294609173u ^ 513628476u); continue; } case 9u: { string fullName; this.descriptorsByName[fullName] = descriptor; arg_1DA_0 = 560751961u; continue; } case 10u: goto IL_220; case 11u: { int num2; arg_1DA_0 = (((num2 != -1) ? 3906432723u : 2856908785u) ^ num * 923807959u); continue; } case 12u: goto IL_227; case 13u: { string fullName; int num2 = DescriptorPool.smethod_2(fullName, '.'); arg_1DA_0 = (num * 2071959698u ^ 1993918755u); continue; } } goto Block_4; } } Block_4: return; IL_227: throw new DescriptorValidationException(descriptor, description); }
internal void AddPackage(string fullName, FileDescriptor file) { int num = DescriptorPool.smethod_2(fullName, '.'); if (num != -1) { goto IL_2D; } goto IL_DD; uint arg_B1_0; IDescriptor descriptor; string text; while (true) { IL_AC: uint num2; switch ((num2 = (arg_B1_0 ^ 3316964695u)) % 8u) { case 0u: arg_B1_0 = (this.descriptorsByName.TryGetValue(fullName, out descriptor) ? 2404316941u : 3896060576u); continue; case 1u: this.AddPackage(DescriptorPool.smethod_3(fullName, 0, num), file); text = DescriptorPool.smethod_4(fullName, num + 1); arg_B1_0 = (num2 * 1743673299u ^ 1753241596u); continue; case 2u: arg_B1_0 = (((descriptor is PackageDescriptor) ? 932590856u : 1724073788u) ^ num2 * 1699437476u); continue; case 3u: goto IL_E6; case 5u: goto IL_DD; case 6u: goto IL_2D; case 7u: this.descriptorsByName[fullName] = new PackageDescriptor(text, fullName, file); arg_B1_0 = 2781272387u; continue; } break; } return; IL_E6: throw new DescriptorValidationException(file, DescriptorPool.smethod_5(new string[] { Module.smethod_33 <string>(3031927268u), text, Module.smethod_35 <string>(2921857439u), descriptor.File.Name, Module.smethod_35 <string>(2292255829u) })); IL_2D: arg_B1_0 = 4212142822u; goto IL_AC; IL_DD: text = fullName; arg_B1_0 = 3564429855u; goto IL_AC; }
private void ImportPublicDependencies(FileDescriptor file) { IEnumerator <FileDescriptor> enumerator = file.PublicDependencies.GetEnumerator(); try { while (true) { IL_AF: uint arg_7C_0 = DescriptorPool.smethod_0(enumerator) ? 483463677u : 1013596277u; while (true) { uint num; switch ((num = (arg_7C_0 ^ 1510700764u)) % 6u) { case 0u: goto IL_AF; case 1u: { FileDescriptor current = enumerator.Current; arg_7C_0 = 2088187487u; continue; } case 2u: arg_7C_0 = 483463677u; continue; case 3u: { FileDescriptor current; arg_7C_0 = ((this.dependencies.Add(current) ? 3551628460u : 3841956582u) ^ num * 990315274u); continue; } case 4u: { FileDescriptor current; this.ImportPublicDependencies(current); arg_7C_0 = (num * 2977631201u ^ 244456022u); continue; } } goto Block_4; } } Block_4 :; } finally { if (enumerator != null) { while (true) { IL_F3 : uint arg_DB_0 = 273087490u; while (true) { uint num; switch ((num = (arg_DB_0 ^ 1510700764u)) % 3u) { case 0u: goto IL_F3; case 1u: DescriptorPool.smethod_1(enumerator); arg_DB_0 = (num * 2366569890u ^ 4210252562u); continue; } goto Block_8; } } Block_8 :; } } }
private static FileDescriptor BuildFrom(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, bool allowUnknownDependencies, GeneratedCodeInfo generatedCodeInfo) { if (dependencies == null) { goto IL_18; } goto IL_122; uint arg_D3_0; FileDescriptor fileDescriptor; int num2; while (true) { IL_CE: uint num; switch ((num = (arg_D3_0 ^ 4161713641u)) % 12u) { case 0u: fileDescriptor.CrossLink(); arg_D3_0 = (num * 1953233347u ^ 2707760628u); continue; case 1u: num2 = 0; arg_D3_0 = 2574715432u; continue; case 2u: num2++; arg_D3_0 = 4243801185u; continue; case 3u: dependencies = new FileDescriptor[0]; arg_D3_0 = (num * 3942966366u ^ 4286440245u); continue; case 4u: arg_D3_0 = ((num2 < proto.Dependency.Count) ? 2982469083u : 3757505837u); continue; case 5u: arg_D3_0 = (num * 314203903u ^ 1276877662u); continue; case 6u: arg_D3_0 = ((!FileDescriptor.smethod_5(dependencies[num2].Name, proto.Dependency[num2])) ? 3773742995u : 2893382989u); continue; case 7u: goto IL_18; case 8u: goto IL_14B; case 10u: goto IL_122; case 11u: goto IL_183; } break; } return(fileDescriptor); IL_14B: throw new DescriptorValidationException(fileDescriptor, FileDescriptor.smethod_6(Module.smethod_37 <string>(2509052754u), proto.Dependency[num2], Module.smethod_35 <string>(3048061080u), dependencies[num2].Name)); IL_183: throw new DescriptorValidationException(fileDescriptor, Module.smethod_33 <string>(2639691648u)); IL_18: arg_D3_0 = 3320637418u; goto IL_CE; IL_122: DescriptorPool pool = new DescriptorPool(dependencies); fileDescriptor = new FileDescriptor(descriptorData, proto, dependencies, pool, allowUnknownDependencies, generatedCodeInfo); arg_D3_0 = ((dependencies.Length != proto.Dependency.Count) ? 2984046962u : 2591580144u); goto IL_CE; }
private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedCodeInfo generatedCodeInfo) { FileDescriptor __4__this; while (true) { IL_113: uint arg_E7_0 = 3109136426u; while (true) { uint num; switch ((num = (arg_E7_0 ^ 2557234891u)) % 8u) { case 0u: pool.AddPackage(this.Package, this); arg_E7_0 = (num * 1105332455u ^ 1354664894u); continue; case 1u: __4__this = this; arg_E7_0 = (num * 4125576103u ^ 2241118048u); continue; case 2u: this.< Dependencies > k__BackingField = new ReadOnlyCollection <FileDescriptor>((FileDescriptor[])FileDescriptor.smethod_0(dependencies)); this.< PublicDependencies > k__BackingField = FileDescriptor.DeterminePublicDependencies(this, proto, dependencies, allowUnknownDependencies); arg_E7_0 = (num * 2070285500u ^ 1583842795u); continue; case 3u: goto IL_113; case 4u: this.< SerializedData > k__BackingField = descriptorData; arg_E7_0 = (num * 559784837u ^ 3768172688u); continue; case 5u: this.< MessageTypes > k__BackingField = DescriptorUtil.ConvertAndMakeReadOnly <DescriptorProto, MessageDescriptor>(proto.MessageType, (DescriptorProto message, int index) => new MessageDescriptor(message, __4__this, null, index, generatedCodeInfo.NestedTypes[index])); arg_E7_0 = (num * 3261531694u ^ 3702070131u); continue; case 7u: this.< DescriptorPool > k__BackingField = pool; this.< Proto > k__BackingField = proto; arg_E7_0 = (num * 2550378934u ^ 3723757811u); continue; } goto Block_1; } } Block_1: this.< EnumTypes > k__BackingField = DescriptorUtil.ConvertAndMakeReadOnly <EnumDescriptorProto, EnumDescriptor>(proto.EnumType, (EnumDescriptorProto enumType, int index) => new EnumDescriptor(enumType, __4__this, null, index, generatedCodeInfo.NestedEnums[index])); this.< Services > k__BackingField = DescriptorUtil.ConvertAndMakeReadOnly <ServiceDescriptorProto, ServiceDescriptor>(proto.Service, (ServiceDescriptorProto service, int index) => new ServiceDescriptor(service, this, index)); }