aboutsummaryrefslogtreecommitdiff
path: root/php/ext/google/protobuf/message.c
diff options
context:
space:
mode:
authorPaul Yang <TeBoring@users.noreply.github.com>2017-01-27 13:17:54 -0800
committerGitHub <noreply@github.com>2017-01-27 13:17:54 -0800
commita323f1e65da2c512f971a2edf1918a0cca340015 (patch)
tree22ae538979fd53567f144a112b069ae2706a03e0 /php/ext/google/protobuf/message.c
parent5af0b547de7aba6d6206943546262cb21fedc721 (diff)
downloadprotobuf-a323f1e65da2c512f971a2edf1918a0cca340015.tar.gz
protobuf-a323f1e65da2c512f971a2edf1918a0cca340015.tar.bz2
protobuf-a323f1e65da2c512f971a2edf1918a0cca340015.zip
Oneof accessor should return the field name that is actually set. (#2631)
Diffstat (limited to 'php/ext/google/protobuf/message.c')
-rw-r--r--php/ext/google/protobuf/message.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c
index 16e397f5..f5a9499d 100644
--- a/php/ext/google/protobuf/message.c
+++ b/php/ext/google/protobuf/message.c
@@ -41,6 +41,7 @@ static zend_function_entry message_methods[] = {
PHP_ME(Message, decode, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, readOneof, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Message, writeOneof, NULL, ZEND_ACC_PROTECTED)
+ PHP_ME(Message, whichOneof, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Message, __construct, NULL, ZEND_ACC_PROTECTED)
{NULL, NULL, NULL}
};
@@ -258,3 +259,22 @@ PHP_METHOD(Message, writeOneof) {
layout_set(msg->descriptor->layout, msg, field, value TSRMLS_CC);
}
+
+PHP_METHOD(Message, whichOneof) {
+ char* oneof_name;
+ int length;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &oneof_name,
+ &length) == FAILURE) {
+ return;
+ }
+
+ MessageHeader* msg =
+ (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ const upb_oneofdef* oneof =
+ upb_msgdef_ntoo(msg->descriptor->msgdef, oneof_name, length);
+ const char* oneof_case_name = layout_get_oneof_case(
+ msg->descriptor->layout, message_data(msg), oneof TSRMLS_CC);
+ RETURN_STRING(oneof_case_name, 1);
+}