If .NET is an option, protobuf-net has this (in the protobuf-net.Reflection
package):

var schema = """
    syntax = "proto3";

    package helloworld;

    // My cool new message
    message MyMessage {
      string some_string = 1;
      repeated int64 some_numbers = 2;
    }
    """;
var set = new FileDescriptorSet();
set.Add("some.proto", source: new StringReader(schema));
set.Process();

foreach (var file in set.Files)
{
    Console.WriteLine($"in {file.Name}");
    foreach (var msg in file.MessageTypes)
    {
        Console.WriteLine(msg.Name);
        foreach (var field in msg.Fields)
        {
            Console.WriteLine($"> {field.Name}");
        }
    }
    Console.WriteLine();
}


This is entirely managed code (i.e. no "shell to protoc"). The API is
basically identical to the Google one - the idea is that the type system is
binary compatible (i.e. you can serialize it as protobuf and you'd get the
same thing that protoc would give, in binary mode)

On Wed, 4 Oct 2023 at 10:02, 'Ran Volkovich' via Protocol Buffers <
[email protected]> wrote:

> Hi,
> There is a way to transform .proto file like
> syntax = "proto3";
>
> package helloworld;
>
> // My cool new message.
> message MyMessage {
> string some_string = 1;
> repeated int64 some_numbers = 2;
> }
> to FileDescriptorProto class from com.google.protobuf jar (or any other
> proto lib that can represent the proto schema)
> without to use protoc to generate descriptor before?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/ad559f9f-8112-4bbe-b0b8-43f4b64d6d60n%40googlegroups.com
> <https://groups.google.com/d/msgid/protobuf/ad559f9f-8112-4bbe-b0b8-43f4b64d6d60n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Regards,

Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CAF95VAxxG9kVyzsCeSQtoMgo5TrtrVZ%3DhU_9mVC6SVc-SSTe1g%40mail.gmail.com.

Reply via email to