diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-09-05 14:10:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-05 14:10:32 -0700 |
commit | 7f8b91f552e80964d995712c26306410854d8ad1 (patch) | |
tree | d00ef6869c14f07672f75e23988a3ab1db20dbf7 /php/ext/google/protobuf/message.c | |
parent | 35b852f5b84c4bd3cd49652e9473a001aa00d295 (diff) | |
download | protobuf-7f8b91f552e80964d995712c26306410854d8ad1.tar.gz protobuf-7f8b91f552e80964d995712c26306410854d8ad1.tar.bz2 protobuf-7f8b91f552e80964d995712c26306410854d8ad1.zip |
Add native php support for Duration. (#3583)
Diffstat (limited to 'php/ext/google/protobuf/message.c')
-rw-r--r-- | php/ext/google/protobuf/message.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 1faf486e..50a0430c 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -586,6 +586,59 @@ PHP_METHOD(Any, is) { } // ----------------------------------------------------------------------------- +// Duration +// ----------------------------------------------------------------------------- + +static zend_function_entry duration_methods[] = { + PHP_ME(Duration, __construct, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Duration, getSeconds, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Duration, setSeconds, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Duration, getNanos, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Duration, setNanos, NULL, ZEND_ACC_PUBLIC) + {NULL, NULL, NULL} +}; + +zend_class_entry* duration_type; + +// Init class entry. +PHP_PROTO_INIT_SUBMSGCLASS_START("Google\\Protobuf\\Duration", + Duration, duration) + zend_class_implements(duration_type TSRMLS_CC, 1, message_type); + zend_declare_property_long(duration_type, "seconds", strlen("seconds"), + 0 ,ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_long(duration_type, "nanos", strlen("nanos"), + 0 ,ZEND_ACC_PRIVATE TSRMLS_CC); +PHP_PROTO_INIT_SUBMSGCLASS_END + +PHP_METHOD(Duration, __construct) { + PHP_PROTO_HASHTABLE_VALUE desc_php = get_ce_obj(duration_type); + if (desc_php == NULL) { + init_generated_pool_once(TSRMLS_C); + const char* generated_file = + "0ae3010a1e676f6f676c652f70726f746f6275662f6475726174696f6e2e" + "70726f746f120f676f6f676c652e70726f746f627566222a0a0844757261" + "74696f6e120f0a077365636f6e6473180120012803120d0a056e616e6f73" + "180220012805427c0a13636f6d2e676f6f676c652e70726f746f62756642" + "0d4475726174696f6e50726f746f50015a2a6769746875622e636f6d2f67" + "6f6c616e672f70726f746f6275662f7074797065732f6475726174696f6e" + "f80101a20203475042aa021e476f6f676c652e50726f746f6275662e5765" + "6c6c4b6e6f776e5479706573620670726f746f33"; + char* binary; + int binary_len; + hex_to_binary(generated_file, &binary, &binary_len); + + internal_add_generated_file(binary, binary_len, generated_pool TSRMLS_CC); + FREE(binary); + } + + MessageHeader* intern = UNBOX(MessageHeader, getThis()); + custom_data_init(duration_type, intern PHP_PROTO_TSRMLS_CC); +} + +PHP_PROTO_FIELD_ACCESSORS(Duration, duration, Seconds, "seconds") +PHP_PROTO_FIELD_ACCESSORS(Duration, duration, Nanos, "nanos") + +// ----------------------------------------------------------------------------- // Timestamp // ----------------------------------------------------------------------------- |