Skip to content

Instantly share code, notes, and snippets.

@joshkel
Created September 25, 2018 02:23
Show Gist options
  • Save joshkel/36183faee736400c0fe1e863867e15ef to your computer and use it in GitHub Desktop.
Save joshkel/36183faee736400c0fe1e863867e15ef to your computer and use it in GitHub Desktop.
Python Protocol Buffers differences
#!/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