상속: global::ProtoBuf.IExtensible
예제 #1
1
 public static void Merge(FileDescriptorSet files, string path, TextWriter stderr, params string[] args)
 {
     if (stderr == null) throw new ArgumentNullException("stderr");
     if (files == null) throw new ArgumentNullException("files");
     if (string.IsNullOrEmpty(path)) throw new ArgumentNullException("path");
     
     bool deletePath = false;
     if(!IsValidBinary(path))
     { // try to use protoc
         path = CompileDescriptor(path, stderr, args);
         deletePath = true;
     }
     try
     {
         using (FileStream stream = File.OpenRead(path))
         {
             Serializer.Merge(stream, files);
         }
     }
     finally
     {
         if(deletePath)
         {
             File.Delete(path);
         }
     }
 }
예제 #2
0
 public void TestProtoInput()
 {
     FileDescriptorSet files = new FileDescriptorSet();
     Assert.AreEqual(0, files.file.Count);
     InputFileLoader.Merge(files, @"ProtoGen\descriptor.proto", Console.Error);
     Assert.AreEqual(1, files.file.Count);
 }
예제 #3
0
        public void TestBinaryInput()
        {
            // compile .proto to .bin
            Process.Start("protoc", @"--descriptor_set_out=ProtoGen\descriptor.bin --include_imports ProtoGen\descriptor.proto").WaitForExit();

            // process .bin
            FileDescriptorSet files = new FileDescriptorSet();
            Assert.AreEqual(0, files.file.Count);
            InputFileLoader.Merge(files, @"ProtoGen\descriptor.bin", Console.Error);
            Assert.AreEqual(1, files.file.Count);
        }
예제 #4
0
 static public void Gen(google.protobuf.FileDescriptorSet set)
 {
     currentSet = set;
     foreach (var proto in set.file)
     {
         foreach (var message in proto.message_type)
         {
             //message.nested_type
             GenMessageParse(message);
         }
     }
     currentSet = null;
 }
예제 #5
0
 public void TestGarbageInput()
 {
     FileDescriptorSet files = new FileDescriptorSet();
     try {
         InputFileLoader.Merge(files, @"ProtoGen\InputLoader.cs", Console.Error);
         Assert.Fail("Should have barfed");
     }
     catch(ProtoParseException ex)
     {
         bool sw = ex.Message.StartsWith("An error occurred parsing InputLoader.cs");
         if (!sw) Assert.Fail("Expected message not found: " + ex.Message);
     }
     catch
     {
         Assert.Fail("Expected ArgumentException");
     }
 }
예제 #6
0
 public FileDescriptorSet LoadTypes(Stream ms = null)
 {
     var files = new FileDescriptorSet();
     var args = string.Join(" ", (_includePaths ?? new string[0])
         .Concat(_addToIncludePath
             ? _paths.Select(Path.GetDirectoryName)
             : new string[0])
         .Where(Directory.Exists)
         .Select(o => o.ToLowerInvariant())
         .Distinct()
         .Select(o => "-I " + o));
     using (var sr = ms != null ? new StreamWriter(ms) : StreamWriter.Null)
     {
         foreach (var path in _paths
             .Where(File.Exists)
             .Select(o => o.ToLowerInvariant())
             .Distinct())
         {
             InputFileLoader.Merge(files, path, sr, args);
         }
     }
     return files;
 }
        private static string LoadFilesAsXml(CommandLineOptions options)
        {
            FileDescriptorSet set = new FileDescriptorSet();

            foreach (string inPath in options.InPaths)
            {
                InputFileLoader.Merge(set, inPath, options.ErrorWriter, options.Arguments.ToArray());
            }

            XmlSerializer xser = new XmlSerializer(typeof(FileDescriptorSet));
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.IndentChars = "  ";
            settings.NewLineHandling = NewLineHandling.Entitize;
            StringBuilder sb = new StringBuilder();
            using (XmlWriter writer = XmlWriter.Create(sb, settings))
            {
                xser.Serialize(writer, set);
            }
            return sb.ToString();
        }
예제 #8
0
 public void TestMissingInput()
 {
     FileDescriptorSet files = new FileDescriptorSet();
     InputFileLoader.Merge(files, @"ProtoGen\NoneSuch.bin", Console.Error);
 }
예제 #9
0
 public void TestEmptyPath()
 {
     FileDescriptorSet files = new FileDescriptorSet();
     InputFileLoader.Merge(files, "", Console.Error);
 }
예제 #10
0
 public void TestNullPath()
 {
     FileDescriptorSet files = new FileDescriptorSet();
     InputFileLoader.Merge(files, null, Console.Error);
 }