How to write your own protobuf code generator

Google protobuf is a good IDL for RPC. But I want to know how to write my own code generator for protobuf.

+5
source share
1 answer

The protoc compiler can output a description of the .proto file in protobuf format. Thus, most of the analysis has been done for you already, and you only need to create the desired result.

The .proto diagram for describing the .proto file is here: https://github.com/google/protobuf/blob/master/src/google/protobuf/descriptor.proto

As an additional step, you can start your generator via "-mygenerator-out =." option on the duct itself: https://developers.google.com/protocol-buffers/docs/reference/other

Here is one (albeit a bit confusing) example of how a code generator can be written in Python: https://github.com/nanopb/nanopb/blob/master/generator/nanopb_generator.py

+4
source

Source: https://habr.com/ru/post/1215031/


All Articles