Generator.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using Google.ProtocolBuffers.DescriptorProtos;
  4. using System.IO;
  5. using Google.ProtocolBuffers.Descriptors;
  6. namespace Google.ProtocolBuffers.ProtoGen {
  7. /// <summary>
  8. /// Code generator for protocol buffers. Only C# is supported at the moment.
  9. /// </summary>
  10. public sealed class Generator {
  11. readonly GeneratorOptions options;
  12. private Generator(GeneratorOptions options) {
  13. options.Validate();
  14. this.options = options;
  15. }
  16. /// <summary>
  17. /// Returns a generator configured with the specified options.
  18. /// </summary>
  19. public static Generator CreateGenerator(GeneratorOptions options) {
  20. return new Generator(options);
  21. }
  22. public void Generate() {
  23. foreach (string inputFile in options.InputFiles) {
  24. FileDescriptorSet descriptorProtos;
  25. using (Stream inputStream = File.OpenRead(inputFile)) {
  26. descriptorProtos = FileDescriptorSet.ParseFrom(inputStream);
  27. }
  28. List<FileDescriptor> descriptors = ConvertDescriptors(descriptorProtos);
  29. }
  30. }
  31. /// <summary>
  32. /// Resolves any dependencies and converts FileDescriptorProtos into FileDescriptors.
  33. /// The list returned is in the same order as the protos are listed in the descriptor set.
  34. /// Note: this method is internal rather than private to allow testing.
  35. /// </summary>
  36. /// <exception cref="DependencyResolutionException">Not all dependencies could be resolved.</exception>
  37. internal static List<FileDescriptor> ConvertDescriptors(FileDescriptorSet descriptorProtos) {
  38. return null;
  39. }
  40. }
  41. }