Skip to content

Instantly share code, notes, and snippets.

@jadeallenx
Created January 10, 2017 22:14
Show Gist options
  • Save jadeallenx/e9e45a5964b444a807a39b804555022d to your computer and use it in GitHub Desktop.
Save jadeallenx/e9e45a5964b444a807a39b804555022d to your computer and use it in GitHub Desktop.
Parsing hex protobuf files in python
>>> import charm.proto.hex_pb_signed_pb2
>>> s = charm.proto.hex_pb_signed_pb2.Signed()
>>> import charm.proto.hex_pb_package_pb2
>>> pkg = charm.proto.hex_pb_package_pb2.Package()
>>> pkgbuf = None
>>> with open("test/gisla.unc") as f:
... pkgbuf = f.read()
...
>>> s.ParseFromString(pkgbuf)
>>> s.payload
'\n7\n\x051.0.0\x12 \ny\xc2\xe1u\xc4 \x8b\x8e=\x89\xc1dp J\xf9\xad5$/:\x93\xc3\xdb\xaa\t\x07y?\x8e\x1b\x1a\x0c\n\x03hut\x12\x051.2.0'
>>> pkg.ParseFromString(s.payload)
>>> pkg.releases
[version: "1.0.0"
checksum: "\ny\302\341u\304 \213\216=\211\301dp J\371\2555$/:\223\303\333\252\t\007y?\216\033"
dependencies {
package: "hut"
requirement: "1.2.0"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment