Last active
May 1, 2021 05:12
-
-
Save ci7lus/8cf90e8524621d25b08f3a878343a4bf to your computer and use it in GitHub Desktop.
usage: python3 protobuf-inspector-config-to-proto.py protobuf_config.py > proto.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import importlib.machinery | |
argv = sys.argv | |
loader = importlib.machinery.SourceFileLoader("types", argv[1]) | |
loaded = loader.load_module() | |
print("""syntax = "proto3"; | |
package packagename; | |
""") | |
for messageName, messageData in loaded.types.items(): | |
print("message", messageName.capitalize(), "{") | |
for num, struc in messageData.items(): | |
if type(struc) is tuple: | |
print(f" {struc[0]} {struc[1]} = {num};") | |
else: | |
print(f" {struc.capitalize()} {struc} = {num};") | |
print("}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment