Skip to content

Commit

Permalink
Write syntax attribute when decoding from bin
Browse files Browse the repository at this point in the history
 - Also writes a reference link back to this repo
  • Loading branch information
Bert-Proesmans committed Jul 15, 2018
1 parent bf0f518 commit 1d69046
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions protobin_to_proto.py
Expand Up @@ -116,11 +116,14 @@ def decompile(self, file, out_dir=".", stdout=False):
descriptors = []

# Discover wire-encoded FileDescriptorProto's
print("Checking for wire-encoded proto files!")
print("Checking for wire-encoded proto files..")
descriptors.extend(self.discover_encoded_file_descriptor(data))
print("")

# Discover GZipped FileDescriptorProto's
print("Checking for GZIPPED proto files!")
print("Checking for GZIPPED proto files..")
descriptors.extend(self.discover_gzipped_file_descriptor(data))
print("")

for descriptor in descriptors:
descriptor_name = descriptor.name
Expand Down Expand Up @@ -255,10 +258,17 @@ def discover_gzipped_file_descriptor(self, data):
return descriptors

def decompile_file_descriptor(self, descriptor):
# deserialize package name and dependencies
# Write meta information of proto file, this is equivalent to a header
if descriptor.HasField("syntax"):
self.write("syntax = \"%s\";\n" % descriptor.syntax)
else:
self.write("syntax = \"proto2\";\n")

if descriptor.HasField("package"):
self.write("package %s;\n" % descriptor.package)

self.write("\n// Proto extractor compiled unit - https://github.com/HearthSim/proto-extractor\n\n")

for dep in descriptor.dependency:
self.write("import \"%s\";\n" % dep)

Expand Down

0 comments on commit 1d69046

Please sign in to comment.