Skip to content

Instantly share code, notes, and snippets.

@ci7lus
Last active May 1, 2021 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ci7lus/8cf90e8524621d25b08f3a878343a4bf to your computer and use it in GitHub Desktop.
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
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