You can parse the .proto file into a serialized FileDescriptorSet like
this: protoc --include_source_info --descriptor_set_out=descriptors.pb
<proto files...>

The --include_source_info flag will cause the descriptors to include more
information about the original .proto file, including the locations of
declarations in the .proto file. I haven't tried this before but in
principle you could use this information to make targeted edits to the
file. In any case parsing the proto file is the easy part because you can
rely on protoc to do that; writing out the modified file is the harder part.

On Wed, May 26, 2021 at 6:35 AM Timo L. <lange.tim...@gmail.com> wrote:

> Hey,
>
> I have to write a proxy that translates message flows from a custom
> message format to protobuf.
> There is quite a lot messages to be converted and hence I want to create a
> proto file generator, preferably in Python (Others possible as well).
>
> With generator I do not mean the protoc compiler, but a library or
> framework that allows me to read a .proto file, modify it's structure and
> write it back.
>
> When doing Internet research I always end up with how to generate python
> code from protos, which is not my question.
>
> Has someone ever seen such framework?
>
> I have also read about Descriptors, but I guess they are rather about
> reading meta information, than creating or modifying files.
>
> Of course I can also read them as plain file and parse the structure
> myself, but hope there is something already available.
>
>
> Thanks!
>
> --
> 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 protobuf+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/CALgCaPteNxt6pOUeCTr8B_uzGCVHh2n%2B2C3U%3DgUFyeO5LFtENQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/protobuf/CALgCaPteNxt6pOUeCTr8B_uzGCVHh2n%2B2C3U%3DgUFyeO5LFtENQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CADqAXr5M3rV%2BRZ1wJXHWcgPJqENTemcoyPpWwdT4xxFKx1z-%3DQ%40mail.gmail.com.

Reply via email to