Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dump example #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ After this, we get:
1 <chunk> = "STARDUST"
2 <varint> = 100

If you would like to a dump a field to a file, perhaps because it contains bytes that are a file, then use `dump` as follows:

~~~ python
types = {
"root": {
1: "dump",
2: "dump",
},
}
~~~

This dumps field 1 and field 2 to the files `dump.0` and `dump.1`.

Here's the list of native types supported:

Wire type | Type | Description
Expand Down
5 changes: 2 additions & 3 deletions lib/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ def parse_enum(self, x, type):
def parse_dump(self, file, type):
chunk = file.read()
filename = self.dump_prefix + str(self.dump_index)
file = open(filename, "w")
file.write(chunk)
file.close()
with open(filename, "wb") as f:
f.write(chunk)
self.dump_index += 1
return "%d bytes written to %s" % (len(chunk), filename)

Expand Down