Created
September 25, 2018 02:23
-
-
Save joshkel/36183faee736400c0fe1e863867e15ef to your computer and use it in GitHub Desktop.
Python Protocol Buffers differences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Test file demonstrating issues from | |
# https://github.com/protocolbuffers/protobuf/pull/5166 | |
# Try running with PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python | |
# and with PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp | |
import subprocess | |
proto_definition = """ | |
syntax = "proto2"; | |
message TestMessage | |
{ | |
optional int32 value = 1; | |
} | |
""" | |
with open('test.proto', 'w') as f: | |
f.write(proto_definition) | |
subprocess.check_call(['protoc', '--python_out=.', 'test.proto']) | |
import test_pb2 # noqa | |
test_message = test_pb2.TestMessage() | |
print(test_message.ParseFromString(b'test')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment