grpc-python: Members of enum with value 0 not printed or converted to Json

30 views
Skip to first unread message

ascani...@gmail.com

unread,
Jan 5, 2017, 10:34:09 PM1/5/17
to grpc.io
I have a message with an enum member. When the value is 0, it is not printed out or added to json with MessageToJson().

python -m grpc_tools.protoc -I . --python_out=. --grpc_python_out=. ./test_service.proto

>>> import test_service_pb2
>>> x = test_service_pb2.TestMsg()
>>> print (x)

>>> x.my_string = "abcd"
>>> x.my_enum = 1
>>> print (x)
my_string: "abcd"
my_enum: ENUMTYPE_ONE

>>> x.my_enum = 0
>>> print (xxy)
my_string: "abcd"

## what happened to my_enum: ENUMTYPE_ZERO ??
python --version 3.5.2

protobuf 3.1.0
grpcio-1.0.4

test_service.proto:
syntax = "proto3";
service TestService {
    rpc TestMethod (TestMsg) returns (TestMsg);
}
message TestMsg {
    string my_string = 1;
    EnumType my_enum = 2;
}
// -----------------------------
enum EnumType {
    ENUMTYPE_ZERO = 0;
    ENUMTYPE_ONE = 1;
}

ascani...@gmail.com

unread,
Jan 5, 2017, 11:00:59 PM1/5/17
to grpc.io
Sorry for the noise:  forgot about default values in protobuf.
Reply all
Reply to author
Forward
0 new messages