summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorKyle Manna <kyle@kylemanna.com>2015-09-19 14:30:21 -0700
committerKyle Manna <kyle@kylemanna.com>2015-09-20 18:48:06 -0700
commit2731fe3e6a4ba6fd858947e343160c95c96042e2 (patch)
tree11c75efc2efbb6de1c42d8b8b5567fd941f3c683 /generator
parent02367d6d77b20cb8bb1dcac4a70ae7d6849a2e1f (diff)
generator: Use python2/3 binary read/write method
* This works with python2 and python3
Diffstat (limited to 'generator')
-rwxr-xr-xgenerator/nanopb_generator.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 17cb674f..c2acb060 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -1440,14 +1440,15 @@ def main_cli():
def main_plugin():
'''Main function when invoked as a protoc plugin.'''
- import sys
+ import io, sys
if sys.platform == "win32":
import os, msvcrt
# Set stdin and stdout to binary mode
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
- data = sys.stdin.read()
+ data = io.open(sys.stdin.fileno(), "rb").read()
+
request = plugin_pb2.CodeGeneratorRequest.FromString(data)
try:
@@ -1490,7 +1491,7 @@ def main_plugin():
f.name = results['sourcename']
f.content = results['sourcedata']
- sys.stdout.write(response.SerializeToString())
+ io.open(sys.stdout.fileno(), "wb").write(response.SerializeToString())
if __name__ == '__main__':
# Check if we are running as a plugin under protoc