Go to the documentation of this file.
32 #include <Zend/zend_exceptions.h>
35 #include "builtin_descriptors.inc"
79 for (
i = 0;
i < strlen(field_name); ++
i) {
80 if (field_name[
i] ==
'_') {
82 }
else if (cap_next) {
84 if (
'a' <= field_name[
i] && field_name[
i] <=
'z') {
85 result[pos++] = field_name[
i] -
'a' +
'A';
87 result[pos++] = field_name[
i];
91 result[pos++] = field_name[
i];
94 strcat(result,
"Entry");
108 zend_class_entry class_type;
109 INIT_CLASS_ENTRY(class_type,
"Google\\Protobuf\\Internal\\GPBType",
111 gpb_type_type = zend_register_internal_class(&class_type TSRMLS_CC);
112 zend_declare_class_constant_long(
gpb_type_type,
STR(
"DOUBLE"), 1 TSRMLS_CC);
115 zend_declare_class_constant_long(
gpb_type_type,
STR(
"UINT64"), 4 TSRMLS_CC);
117 zend_declare_class_constant_long(
gpb_type_type,
STR(
"FIXED64"), 6 TSRMLS_CC);
118 zend_declare_class_constant_long(
gpb_type_type,
STR(
"FIXED32"), 7 TSRMLS_CC);
120 zend_declare_class_constant_long(
gpb_type_type,
STR(
"STRING"), 9 TSRMLS_CC);
121 zend_declare_class_constant_long(
gpb_type_type,
STR(
"GROUP"), 10 TSRMLS_CC);
122 zend_declare_class_constant_long(
gpb_type_type,
STR(
"MESSAGE"), 11 TSRMLS_CC);
123 zend_declare_class_constant_long(
gpb_type_type,
STR(
"BYTES"), 12 TSRMLS_CC);
124 zend_declare_class_constant_long(
gpb_type_type,
STR(
"UINT32"), 13 TSRMLS_CC);
130 zend_declare_class_constant_long(
gpb_type_type,
STR(
"SINT32"), 17 TSRMLS_CC);
131 zend_declare_class_constant_long(
gpb_type_type,
STR(
"SINT64"), 18 TSRMLS_CC);
164 #if PHP_MAJOR_VERSION < 7
165 const char* classname =
intern->klass->name;
167 const char* classname = ZSTR_VAL(
intern->klass->name);
180 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l", &
index) ==
182 zend_error(E_USER_ERROR,
"Expect integer for index.\n");
189 zend_error(E_USER_ERROR,
"Cannot get element at %ld.\n",
index);
201 if (field_hashtable_value ==
NULL) {
202 #if PHP_MAJOR_VERSION < 7
203 MAKE_STD_ZVAL(field_hashtable_value);
206 Z_DELREF_P(field_hashtable_value);
208 field_hashtable_value =
218 #if PHP_MAJOR_VERSION < 7
219 RETURN_ZVAL(field_hashtable_value, 1, 0);
222 RETURN_OBJ(field_hashtable_value);
233 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l", &
index) ==
235 zend_error(E_USER_ERROR,
"Expect integer for index.\n");
242 zend_error(E_USER_ERROR,
"Cannot get element at %ld.\n",
index);
256 oneof_php->oneofdef = oneof;
275 "Google\\Protobuf\\EnumDescriptor");
281 self->enumdef =
NULL;
287 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l", &
index) ==
289 zend_error(E_USER_ERROR,
"Expect integer for index.\n");
296 zend_error(E_USER_ERROR,
"Cannot get element at %ld.\n",
index);
330 "Google\\Protobuf\\EnumValueDescriptor");
347 RETURN_LONG(
intern->number);
366 "Google\\Protobuf\\FieldDescriptor");
372 self->fielddef =
NULL;
377 #define CASE(descriptor_type, type) \
378 case UPB_DESCRIPTOR_TYPE_##descriptor_type: \
379 return UPB_TYPE_##type;
382 CASE(DOUBLE, DOUBLE);
384 CASE(STRING, STRING);
386 CASE(MESSAGE, MESSAGE);
387 CASE(GROUP, MESSAGE);
391 CASE(UINT32, UINT32);
392 CASE(UINT64, UINT64);
395 CASE(FIXED32, UINT32);
396 CASE(FIXED64, UINT64);
397 CASE(SFIXED32, INT32);
398 CASE(SFIXED64, INT64);
404 zend_error(E_ERROR,
"Unknown field type.");
437 zend_throw_exception_ex(
NULL, 0 TSRMLS_CC,
438 "Cannot get enum type for non-enum field '%s'",
445 #if PHP_MAJOR_VERSION < 7
446 RETURN_ZVAL(
desc, 1, 0);
456 zend_throw_exception_ex(
457 NULL, 0 TSRMLS_CC,
"Cannot get message type for non-message field '%s'",
464 #if PHP_MAJOR_VERSION < 7
465 RETURN_ZVAL(
desc, 1, 0);
478 PHP_ME(
Oneof, getField,
NULL, ZEND_ACC_PUBLIC)
479 PHP_ME(
Oneof, getFieldCount,
NULL, ZEND_ACC_PUBLIC)
484 "Google\\Protobuf\\OneofDescriptor");
490 self->oneofdef =
NULL;
501 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l", &
index) ==
503 zend_error(E_USER_ERROR,
"Expect integer for index.\n");
510 zend_error(E_USER_ERROR,
"Cannot get element at %ld.\n",
index);
522 if (field_hashtable_value ==
NULL) {
523 #if PHP_MAJOR_VERSION < 7
524 MAKE_STD_ZVAL(field_hashtable_value);
528 field_hashtable_value =
537 #if PHP_MAJOR_VERSION < 7
538 RETURN_ZVAL(field_hashtable_value, 1, 0);
541 RETURN_OBJ(field_hashtable_value);
556 ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
564 ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
570 "Google\\Protobuf\\DescriptorPool");
572 "Google\\Protobuf\\Internal\\DescriptorPool");
575 #if PHP_MAJOR_VERSION < 7
586 #if PHP_MAJOR_VERSION < 7
590 internal_descriptor_pool_type->create_object(
591 internal_descriptor_pool_type TSRMLS_CC));
594 descriptor_pool_type TSRMLS_CC));
597 internal_descriptor_pool_type TSRMLS_CC);
601 descriptor_pool_type->create_object(descriptor_pool_type TSRMLS_CC);
609 pool->fill_handler_cache =
642 zend_error(E_USER_ERROR,
643 "Enum definition does not contain a value for '0'.");
655 zend_error(E_ERROR,
"Required fields are unsupported in proto3.");
662 #if PHP_MAJOR_VERSION < 7
672 #if PHP_MAJOR_VERSION < 7
682 const char *php_namespace,
684 size_t fullname_len = strlen(fullname);
685 size_t package_len = 0;
686 size_t prefix_len = 0;
687 size_t namespace_len = 0;
688 size_t length = fullname_len;
689 int i, segment, classname_start = 0;
695 prefix_len = strlen(
prefix);
697 if (php_namespace !=
NULL) {
698 namespace_len = strlen(php_namespace);
702 if (package_len > 0) {
704 for (
i = 0;
i < package_len;
i++) {
712 classname_start = package_len + 1;
717 for (
i = classname_start;
i < fullname_len;
i++) {
718 if (fullname[
i] ==
'.') {
722 if (prefix_len == 0) {
725 length += prefix_len * segment;
729 return length + namespace_len + 2;
735 memset(lower, 0,
length + 1);
736 memcpy(lower, segment,
length);
739 lower[
i] = (char)tolower(lower[
i]);
749 const char *prefix_given,
750 const char *package_name,
754 if (prefix_given !=
NULL && strcmp(prefix_given,
"") != 0) {
756 strlen(prefix_given),
NULL);
759 if (package_name !=
NULL &&
760 strcmp(
"google.protobuf", package_name) == 0) {
771 if (use_camel && (segment[0] <
'A' || segment[0] >
'Z')) {
772 char first = segment[0] + (
'A' -
'a');
782 if (php_namespace !=
NULL) {
788 size_t package_len = strlen(
package);
789 while (
i < package_len) {
791 while (j < package_len &&
package[j] !=
'.') {
806 bool use_nested_submsg) {
807 int classname_start = 0;
809 size_t package_len = strlen(
package);
810 classname_start = package_len == 0 ? 0 : package_len + 1;
812 size_t fullname_len = strlen(fullname);
813 bool is_first_segment =
true;
815 int i = classname_start, j;
816 while (
i < fullname_len) {
818 while (j < fullname_len && fullname[j] !=
'.') {
821 if (use_nested_submsg || is_first_segment && j == fullname_len) {
824 is_first_segment =
false;
826 if (j != fullname_len) {
827 if (use_nested_submsg) {
838 const char *fullname,
840 bool use_nested_submsg TSRMLS_DC) {
844 const char *
package = upb_filedef_package(file);
847 size_t classname_len =
850 zend_class_entry* ret;
863 "Generated message class %s hasn't been defined (%s, %s, %s, %s)",
880 for (
i = 0;
i <
n;
i++) {
900 data, data_len, arena);
903 zend_error(E_ERROR,
"Failed to parse binary descriptor\n");
910 zend_error(E_ERROR,
"Serialized descriptors should have exactly one file");
921 descriptor_proto_len,
pool, arena)) {
934 bool use_nested_submsg TSRMLS_DC) {
963 use_nested_submsg TSRMLS_CC);
978 use_nested_submsg TSRMLS_CC);
990 zend_bool use_nested_submsg =
false;
993 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s|b",
994 &
data, &data_len, &use_nested_submsg) ==
1001 use_nested_submsg TSRMLS_CC);
1008 char *classname =
NULL;
1011 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s", &classname,
1012 &classname_len) == FAILURE) {
1033 #if PHP_MAJOR_VERSION < 7
1034 RETURN_ZVAL(
desc, 1, 0);
1045 char *classname =
NULL;
1048 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s", &classname,
1049 &classname_len) == FAILURE) {
1070 #if PHP_MAJOR_VERSION < 7
1071 RETURN_ZVAL(
desc, 1, 0);
int32_t upb_enum_iter_number(upb_enum_iter *iter)
static zend_function_entry field_descriptor_methods[]
const upb_msgdef * msgdef
#define UNBOX_HASHTABLE_VALUE(class_name, val)
const upb_oneofdef * upb_msg_iter_oneof(const upb_msg_oneof_iter *iter)
upb_fieldtype_t to_fieldtype(upb_descriptortype_t type)
void upb_enum_next(upb_enum_iter *iter)
static void descriptor_init_c_instance(Descriptor *intern TSRMLS_DC)
GLuint const GLchar * name
void upb_status_clear(upb_status *status)
zend_class_entry * oneof_descriptor_type
int upb_filedef_msgcount(const upb_filedef *f)
UPB_INLINE upb_strview const * google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len)
static void oneof_descriptor_free_c(Oneof *object TSRMLS_DC)
static int16_t lookup[CNT]
UPB_INLINE upb_arena * upb_arena_new()
bool upb_msgdef_mapentry(const upb_msgdef *m)
const UPB_INLINE google_protobuf_FileDescriptorProto *const * google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg, size_t *len)
const upb_fielddef * fielddef
void add_ce_obj(const void *ce, PHP_PROTO_HASHTABLE_VALUE value)
GLenum GLuint GLenum GLsizei length
const upb_filedef * parse_and_add_descriptor(const char *data, PHP_PROTO_SIZE data_len, InternalDescriptorPool *pool, upb_arena *arena)
upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f)
static void descriptor_pool_init_c_instance(DescriptorPool *pool TSRMLS_DC)
const char * upb_enumdef_iton(const upb_enumdef *def, int32_t num)
void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m)
upb_handlercache * upb_pb_encoder_newcache()
static void descriptor_free_c(Descriptor *object TSRMLS_DC)
static void fill_segment(const char *segment, int length, stringsink *classname, bool use_camel)
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
static void internal_descriptor_pool_free_c(InternalDescriptorPool *object TSRMLS_DC)
ROSCONSOLE_CONSOLE_IMPL_DECL std::string getName(void *handle)
static zend_function_entry descriptor_methods[]
const Message * descriptor_proto
void add_handlers_for_message(const void *closure, upb_handlers *h)
size_t stringsink_string(void *_sink, const void *hd, const char *ptr, size_t len, const upb_bufhandle *handle)
void gpb_type_init(TSRMLS_D)
#define PHP_PROTO_HASHTABLE_VALUE
#define PHP_PROTO_CE_DECLARE
const upb_enumdef * upb_fielddef_enumsubdef(const upb_fielddef *f)
int upb_oneofdef_numfields(const upb_oneofdef *o)
static void enum_descriptor_init_c_instance(EnumDescriptor *intern TSRMLS_DC)
#define PHP_PROTO_CE_UNREF(ce)
upb_symtab * upb_symtab_new()
#define CREATE_HASHTABLE_VALUE(OBJ, WRAPPED_OBJ, OBJ_TYPE, OBJ_CLASS_ENTRY)
upb_handlercache * upb_json_printer_newcache(bool preserve_proto_fieldnames)
static void internal_descriptor_pool_init_c_instance(InternalDescriptorPool *pool TSRMLS_DC)
static void validate_enumdef(const upb_enumdef *enumdef)
UPB_INLINE google_protobuf_FileDescriptorSet * google_protobuf_FileDescriptorSet_parse(const char *buf, size_t size, upb_arena *arena)
static void enum_value_descriptor_init_c_instance(EnumValueDescriptor *intern TSRMLS_DC)
upb_handlercache * upb_handlercache_new(upb_handlers_callback *callback, const void *closure)
static zend_class_entry * register_class(const upb_filedef *file, const char *fullname, PHP_PROTO_HASHTABLE_VALUE desc_php, bool use_nested_submsg TSRMLS_DC)
static void descriptor_pool_free_c(DescriptorPool *object TSRMLS_DC)
struct InternalDescriptorPool InternalDescriptorPool
#define UNBOX(class_name, val)
struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto
int upb_enumdef_numvals(const upb_enumdef *e)
#define ALLOC_N(class_name, n)
void upb_pbcodecache_free(upb_pbcodecache *c)
static const char prefix[]
void upb_handlercache_free(upb_handlercache *cache)
InternalDescriptorPool * generated_pool
void free_layout(MessageLayout *layout)
bool upb_fielddef_ismap(const upb_fielddef *f)
void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m)
void add_def_obj(const void *def, PHP_PROTO_HASHTABLE_VALUE value)
int upb_msgdef_numoneofs(const upb_msgdef *m)
const char * upb_enumdef_fullname(const upb_enumdef *e)
void upb_arena_free(upb_arena *a)
DEFINE_CLASS(Descriptor, descriptor, "Google\\Protobuf\\Descriptor")
#define PHP_PROTO_RETVAL_STRINGL(s, len, copy)
UPB_INLINE upb_strview upb_strview_makez(const char *data)
const char * upb_oneofdef_name(const upb_oneofdef *o)
struct EnumValueDescriptor EnumValueDescriptor
#define CASE(descriptor_type, type)
bool depends_on_descriptor(const google_protobuf_FileDescriptorProto *file)
zval * internal_generated_pool_php
void upb_json_codecache_free(upb_json_codecache *c)
zend_class_entry * field_descriptor_type
const char * upb_fielddef_name(const upb_fielddef *f)
static void field_descriptor_free_c(FieldDescriptor *object TSRMLS_DC)
upb_json_codecache * upb_json_codecache_new()
static void enum_descriptor_free_c(EnumDescriptor *object TSRMLS_DC)
static void validate_msgdef(const upb_msgdef *msgdef)
bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter)
const FieldDescriptor * field
PHP_METHOD(Descriptor, getClass)
const char * upb_filedef_phpprefix(const upb_filedef *f)
InternalDescriptorPool * pool
static zend_function_entry enum_value_descriptor_methods[]
void stringsink_uninit(stringsink *sink)
zend_class_entry * enum_descriptor_type
static void fill_prefix(const char *segment, int length, const char *prefix_given, const char *package_name, stringsink *classname)
void upb_oneof_next(upb_oneof_iter *iter)
upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f)
upb_fielddef * upb_msg_iter_field(const upb_msg_field_iter *iter)
void upb_symtab_free(upb_symtab *s)
static zend_function_entry gpb_type_methods[]
bool upb_enum_done(upb_enum_iter *iter)
static void enum_value_descriptor_free_c(EnumValueDescriptor *object TSRMLS_DC)
upb_fielddef * upb_oneof_iter_field(const upb_oneof_iter *iter)
void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o)
void build_class_from_descriptor(PHP_PROTO_HASHTABLE_VALUE php_descriptor TSRMLS_DC)
#define ZVAL_OBJ(zval_ptr, call_create)
const upb_msgdef * upb_fielddef_msgsubdef(const upb_fielddef *f)
const upb_filedef * upb_symtab_addfile(upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto, upb_status *status)
void upb_msg_field_next(upb_msg_field_iter *iter)
PHP_PROTO_HASHTABLE_VALUE get_def_obj(const void *def)
static void field_descriptor_init_c_instance(FieldDescriptor *intern TSRMLS_DC)
int upb_msgdef_numfields(const upb_msgdef *m)
zend_class_entry * gpb_type_type
VALUE enum_descriptor(VALUE self)
UPB_INLINE bool upb_strview_eql(upb_strview a, upb_strview b)
static zend_function_entry oneof_descriptor_methods[]
static void append_map_entry_name(char *result, const char *field_name, int pos)
const char * upb_enum_iter_name(upb_enum_iter *iter)
bool upb_msg_field_done(const upb_msg_field_iter *iter)
struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet
void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e)
static void fill_namespace(const char *package, const char *php_namespace, stringsink *classname)
#define php_proto_zend_lookup_class(name, name_length, ce)
uint32_t upb_fielddef_number(const upb_fielddef *f)
static zend_function_entry descriptor_pool_methods[]
upb_label_t upb_fielddef_label(const upb_fielddef *f)
void stringsink_init(stringsink *sink)
int upb_filedef_enumcount(const upb_filedef *f)
bool upb_oneof_done(upb_oneof_iter *iter)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
PHP_PROTO_HASHTABLE_VALUE get_ce_obj(const void *ce)
static void oneof_descriptor_init_c_instance(Oneof *pool TSRMLS_DC)
static size_t classname_len_max(const char *fullname, const char *package, const char *php_namespace, const char *prefix)
const char * upb_status_errmsg(const upb_status *status)
zval * generated_pool_php
static zend_function_entry internal_descriptor_pool_methods[]
static void fill_classname(const char *fullname, const char *package, const char *prefix, stringsink *classname, bool use_nested_submsg)
void internal_add_generated_file(const char *data, PHP_PROTO_SIZE data_len, InternalDescriptorPool *pool, bool use_nested_submsg TSRMLS_DC)
upb_pbcodecache * upb_pbcodecache_new(upb_handlercache *dest)
upb_strtable_uninit & intern
void add_proto_obj(const char *proto, PHP_PROTO_HASHTABLE_VALUE value)
const char * upb_filedef_phpnamespace(const upb_filedef *f)
const upb_filedef * upb_symtab_lookupfile(const upb_symtab *s, const char *name)
void init_generated_pool_once(TSRMLS_D)
void upb_msg_oneof_next(upb_msg_oneof_iter *iter)
const upb_enumdef * enumdef
static void check_upb_status(const upb_status *status, const char *msg)
bool is_reserved_name(const char *name)
const char * upb_msgdef_fullname(const upb_msgdef *m)
bool upb_ok(const upb_status *status)
const upb_msgdef * upb_filedef_msg(const upb_filedef *f, int i)
zend_class_entry * enum_value_descriptor_type
#define HASHTABLE_VALUE_CE(val)
zend_class_entry * descriptor_type
const upb_enumdef * upb_filedef_enum(const upb_filedef *f, int i)
static bool is_reserved(const char *segment, int length)
static zend_function_entry enum_descriptor_methods[]
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:49