Thanks for that hint!
I had a deeper look.
There is

*std::string Descriptor::DebugString() const*
*Write the contents of this descriptor in a human-readable form.*
*Output will be suitable for re-parsing.*

available in the C++ API, that would do the formatting back to a .proto.
But I cannot find something similar in Python3.

Any hint someone?

[email protected] schrieb am Mittwoch, 26. Mai 2021 um 15:58:36 UTC+2:

> 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. <[email protected]> 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 [email protected].
>> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/67f691c8-3dbe-47a7-bd11-2562e43f5218n%40googlegroups.com.

Reply via email to