Classes | Functions | Variables
protobuf/php/ext/google/protobuf/message.c File Reference
#include "message.h"
#include <inttypes.h>
#include <php.h>
#include <stdlib.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_inheritance.h>
#include "arena.h"
#include "array.h"
#include "convert.h"
#include "def.h"
#include "map.h"
#include "php-upb.h"
#include "protobuf.h"
#include "wkt.inc"
Include dependency graph for protobuf/php/ext/google/protobuf/message.c:

Go to the source code of this file.

Classes

struct  Message
 

Functions

static const upb_fielddefget_field (Message *msg, PROTO_STR *member)
 
static zend_object * Message_clone_obj (PROTO_VAL *object)
 
static int Message_compare_objects (zval *m1, zval *m2)
 
static zend_object * Message_create (zend_class_entry *class_type)
 
static void Message_dtor (zend_object *obj)
 
static void Message_get (Message *intern, const upb_fielddef *f, zval *rv)
 
static HashTable * Message_get_properties (PROTO_VAL *object)
 
static zval * Message_get_property_ptr_ptr (PROTO_VAL *object, PROTO_STR *member, int type, void **cache_slot)
 
void Message_GetPhpWrapper (zval *val, const Descriptor *desc, upb_msg *msg, zval *arena)
 
bool Message_GetUpbMessage (zval *val, const Descriptor *desc, upb_arena *arena, upb_msg **msg)
 
static upb_msgval Message_getval (Message *intern, const char *field_name)
 
static int Message_has_property (PROTO_VAL *obj, PROTO_STR *member, int has_set_exists, void **cache_slot)
 
bool Message_InitFromPhp (upb_msg *msg, const upb_msgdef *m, zval *init, upb_arena *arena)
 
static void Message_Initialize (Message *intern, const Descriptor *desc)
 
void Message_ModuleInit ()
 
static zval * Message_read_property (PROTO_VAL *obj, PROTO_STR *member, int type, void **cache_slot, zval *rv)
 
static bool Message_set (Message *intern, const upb_fielddef *f, zval *val)
 
static void Message_setval (Message *intern, const char *field_name, upb_msgval val)
 
static void Message_SuppressDefaultProperties (zend_class_entry *class_type)
 
static void Message_unset_property (PROTO_VAL *obj, PROTO_STR *member, void **cache_slot)
 
static PROTO_RETURN_VAL Message_write_property (PROTO_VAL *obj, PROTO_STR *member, zval *val, void **cache_slot)
 
static bool MessageEq (const upb_msg *m1, const upb_msg *m2, const upb_msgdef *m)
 
 PHP_METHOD (google_protobuf_Any, is)
 
 PHP_METHOD (google_protobuf_Any, pack)
 
 PHP_METHOD (google_protobuf_Any, unpack)
 
 PHP_METHOD (google_protobuf_Timestamp, fromDateTime)
 
 PHP_METHOD (google_protobuf_Timestamp, toDateTime)
 
 PHP_METHOD (Message, __construct)
 
 PHP_METHOD (Message, clear)
 
 PHP_METHOD (Message, discardUnknownFields)
 
 PHP_METHOD (Message, hasOneof)
 
 PHP_METHOD (Message, mergeFrom)
 
 PHP_METHOD (Message, mergeFromJsonString)
 
 PHP_METHOD (Message, mergeFromString)
 
 PHP_METHOD (Message, readOneof)
 
 PHP_METHOD (Message, readWrapperValue)
 
 PHP_METHOD (Message, serializeToJsonString)
 
 PHP_METHOD (Message, serializeToString)
 
 PHP_METHOD (Message, whichOneof)
 
 PHP_METHOD (Message, writeOneof)
 
 PHP_METHOD (Message, writeWrapperValue)
 
static upb_msgval StringVal (upb_strview view)
 
static bool StrViewEq (upb_strview view, const char *str)
 
static bool TryStripUrlPrefix (upb_strview *str)
 
bool ValueEq (upb_msgval val1, upb_msgval val2, TypeInfo type)
 

Variables

zend_class_entry * message_ce
 
static zend_function_entry Message_methods []
 
static zend_object_handlers message_object_handlers
 
static const char TYPE_URL_PREFIX [] = "type.googleapis.com/"
 

Function Documentation

◆ get_field()

static const upb_fielddef* get_field ( Message msg,
PROTO_STR member 
)
static

get_field()

Helper function to look up a field given a member name (as a string).

Definition at line 113 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_clone_obj()

static zend_object* Message_clone_obj ( PROTO_VAL object)
static

Message_clone_obj()

Object handler for cloning an object in PHP. Called when PHP code does:

$msg2 = clone $msg;

Definition at line 410 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_compare_objects()

static int Message_compare_objects ( zval *  m1,
zval *  m2 
)
static

Message_compare_objects()

Object handler for comparing two message objects. Called whenever PHP code does:

$m1 == $m2

Definition at line 239 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_create()

static zend_object* Message_create ( zend_class_entry *  class_type)
static

Message_create()

PHP class entry function to allocate and initialize a new Message object.

Definition at line 85 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_dtor()

static void Message_dtor ( zend_object *  obj)
static

Message_dtor()

Object handler to destroy a Message. This releases all resources associated with the message. Note that it is possible to access a destroyed object from PHP in rare cases.

Definition at line 101 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_get()

static void Message_get ( Message intern,
const upb_fielddef f,
zval *  rv 
)
static

Definition at line 126 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_get_properties()

static HashTable* Message_get_properties ( PROTO_VAL object)
static

Message_get_properties()

Object handler for the get_properties event in PHP. This returns a HashTable of our internal properties. We don't support this, so we return NULL.

Definition at line 428 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_get_property_ptr_ptr()

static zval* Message_get_property_ptr_ptr ( PROTO_VAL object,
PROTO_STR member,
int  type,
void **  cache_slot 
)
static

Message_get_property_ptr_ptr()

Object handler for the get_property_ptr_ptr event in PHP. This returns a reference to our internal properties. We don't support this, so we return NULL.

Definition at line 397 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_GetPhpWrapper()

void Message_GetPhpWrapper ( zval *  val,
const Descriptor desc,
upb_msg msg,
zval *  arena 
)

Definition at line 436 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_GetUpbMessage()

bool Message_GetUpbMessage ( zval *  val,
const Descriptor desc,
upb_arena arena,
upb_msg **  msg 
)

Definition at line 456 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_getval()

static upb_msgval Message_getval ( Message intern,
const char *  field_name 
)
static

Definition at line 1111 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_has_property()

static int Message_has_property ( PROTO_VAL obj,
PROTO_STR member,
int  has_set_exists,
void **  cache_slot 
)
static

Message_has_property()

Object handler for testing whether a property exists. Called when PHP code does any of:

isset($message->foobar); property_exists($message->foobar);

Note that all properties of generated messages are private, so this should only be possible to invoke from generated code, which has accessors like this (if the field has presence):

public function hasOptionalInt32() { return isset($this->optional_int32); }

Definition at line 267 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_InitFromPhp()

bool Message_InitFromPhp ( upb_msg msg,
const upb_msgdef m,
zval *  init,
upb_arena arena 
)

Message_InitFromPhp()

Helper method to handle the initialization of a message from a PHP value, eg.

$m = new TestMessage([ 'optional_int32' => -42, 'optional_bool' => true, 'optional_string' => 'a', 'optional_enum' => TestEnum::ONE, 'optional_message' => new Sub([ 'a' => 33 ]), 'repeated_int32' => [-42, -52], 'repeated_enum' => [TestEnum::ZERO, TestEnum::ONE], 'repeated_message' => [new Sub(['a' => 34]), new Sub(['a' => 35])], 'map_int32_int32' => [-62 => -62], 'map_int32_enum' => [1 => TestEnum::ONE], 'map_int32_message' => [1 => new Sub(['a' => 36])], ]);

The initializer must be an array.

Definition at line 504 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_Initialize()

static void Message_Initialize ( Message intern,
const Descriptor desc 
)
static

Definition at line 563 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_ModuleInit()

void Message_ModuleInit ( )

Message_ModuleInit()

Called when the C extension is loaded to register all types.

Definition at line 1368 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_read_property()

static zval* Message_read_property ( PROTO_VAL obj,
PROTO_STR member,
int  type,
void **  cache_slot,
zval *  rv 
)
static

Message_read_property()

Object handler for reading a property in PHP. Called when PHP code does:

$x = $message->foobar;

Note that all properties of generated messages are private, so this should only be possible to invoke from generated code, which has accessors like:

public function getOptionalInt32() { return $this->optional_int32; }

We lookup the field and return the scalar, RepeatedField, or MapField for this field.

Definition at line 339 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_set()

static bool Message_set ( Message intern,
const upb_fielddef f,
zval *  val 
)
static

Definition at line 146 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_setval()

static void Message_setval ( Message intern,
const char *  field_name,
upb_msgval  val 
)
static

Definition at line 1117 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_SuppressDefaultProperties()

static void Message_SuppressDefaultProperties ( zend_class_entry *  class_type)
static

Definition at line 63 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_unset_property()

static void Message_unset_property ( PROTO_VAL obj,
PROTO_STR member,
void **  cache_slot 
)
static

Message_unset_property()

Object handler for unsetting a property. Called when PHP code calls:

unset($message->foobar);

Note that all properties of generated messages are private, so this should only be possible to invoke from generated code, which has accessors like this (if the field has presence):

public function clearOptionalInt32() { unset($this->optional_int32); }

Definition at line 302 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_write_property()

static PROTO_RETURN_VAL Message_write_property ( PROTO_VAL obj,
PROTO_STR member,
zval *  val,
void **  cache_slot 
)
static

Message_write_property()

Object handler for writing a property in PHP. Called when PHP code does:

$message->foobar = $x;

Note that all properties of generated messages are private, so this should only be possible to invoke from generated code, which has accessors like:

public function setOptionalInt32($var) { GPBUtil::checkInt32($var); $this->optional_int32 = $var;

return $this; }

The C extension version of checkInt32() doesn't actually check anything, so we perform all checking and conversion in this function.

Definition at line 370 of file protobuf/php/ext/google/protobuf/message.c.

◆ MessageEq()

static bool MessageEq ( const upb_msg m1,
const upb_msg m2,
const upb_msgdef m 
)
static

◆ PHP_METHOD() [1/19]

PHP_METHOD ( google_protobuf_Any  ,
is   
)

Definition at line 1229 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [2/19]

PHP_METHOD ( google_protobuf_Any  ,
pack   
)

Definition at line 1192 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [3/19]

PHP_METHOD ( google_protobuf_Any  ,
unpack   
)

Definition at line 1145 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [4/19]

PHP_METHOD ( google_protobuf_Timestamp  ,
fromDateTime   
)

Definition at line 1250 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [5/19]

PHP_METHOD ( google_protobuf_Timestamp  ,
toDateTime   
)

Definition at line 1323 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [6/19]

PHP_METHOD ( Message  ,
__construct   
)

Message::__construct()

Constructor for Message.

Parameters
arrayMap of initial values ['k' = val]

Definition at line 575 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [7/19]

PHP_METHOD ( Message  ,
clear   
)

Message::clear()

Clears all fields of this message.

Definition at line 628 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [8/19]

PHP_METHOD ( Message  ,
discardUnknownFields   
)

Message::discardUnknownFields()

Discards any unknown fields for this message or any submessages.

Definition at line 618 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [9/19]

PHP_METHOD ( Message  ,
hasOneof   
)

Message::hasOneof()

Returns the presence of the given oneof field, given a field number. Called from generated code methods such as:

public function hasDoubleValueOneof() { return $this->hasOneof(10); }

Returns
boolean

Definition at line 959 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [10/19]

PHP_METHOD ( Message  ,
mergeFrom   
)

Message::mergeFrom()

Merges from the given message, which must be of the same class as us.

Parameters
objectMessage to merge from.

Definition at line 639 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [11/19]

PHP_METHOD ( Message  ,
mergeFromJsonString   
)

Message::mergeFromJsonString()

Merges the JSON data parsed from the given string.

Parameters
stringSerialized JSON data.

Definition at line 733 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [12/19]

PHP_METHOD ( Message  ,
mergeFromString   
)

Message::mergeFromString()

Merges from the given string.

Parameters
stringBinary protobuf data to merge.

Definition at line 679 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [13/19]

PHP_METHOD ( Message  ,
readOneof   
)

Message::readOneof()

Returns the contents of the given oneof field, given a field number. Called from generated code methods such as:

public function getDoubleValueOneof() { return $this->readOneof(10); }

Returns
object The oneof's field value.

Definition at line 992 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [14/19]

PHP_METHOD ( Message  ,
readWrapperValue   
)

Message::readWrapperValue()

Returns an unboxed value for the given field. This is called from generated methods for wrapper fields, eg.

public function getDoubleValueUnwrapped() { return $this->readWrapperValue("double_value"); }

Returns
Unwrapped field value or null.

Definition at line 827 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [15/19]

PHP_METHOD ( Message  ,
serializeToJsonString   
)

Message::serializeToJsonString()

Serializes this object to JSON.

Returns
string Serialized JSON data.

Definition at line 773 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [16/19]

PHP_METHOD ( Message  ,
serializeToString   
)

Message::serializeToString()

Serializes this message instance to protobuf data.

Returns
string Serialized protobuf data.

Definition at line 708 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [17/19]

PHP_METHOD ( Message  ,
whichOneof   
)

Message::whichOneof()

Given a oneof name, returns the name of the field that is set for this oneof, or otherwise the empty string.

Returns
string The field name in this oneof that is currently set.

Definition at line 923 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [18/19]

PHP_METHOD ( Message  ,
writeOneof   
)

Message::writeOneof()

Sets the contents of the given oneof field, given a field number. Called from generated code methods such as:

public function setDoubleValueOneof($var) { GPBUtil::checkMessage($var, \Google\Protobuf\DoubleValue::class); $this->writeOneof(10, $var);

return $this; }

The C extension version of GPBUtil::check*() does nothing, so we perform all type checking and conversion here.

Parameters
integerThe field number we are setting.
objectThe field value we want to set.

Definition at line 1042 of file protobuf/php/ext/google/protobuf/message.c.

◆ PHP_METHOD() [19/19]

PHP_METHOD ( Message  ,
writeWrapperValue   
)

Message::writeWrapperValue()

Sets the given wrapper field to the given unboxed value. This is called from generated methods for wrapper fields, eg.

public function setDoubleValueUnwrapped($var) { $this->writeWrapperValue("double_value", $var); return $this; }

Parameters
Unwrappedfield value or null.

Definition at line 873 of file protobuf/php/ext/google/protobuf/message.c.

◆ StringVal()

static upb_msgval StringVal ( upb_strview  view)
static

Definition at line 1124 of file protobuf/php/ext/google/protobuf/message.c.

◆ StrViewEq()

static bool StrViewEq ( upb_strview  view,
const char *  str 
)
static

Definition at line 1140 of file protobuf/php/ext/google/protobuf/message.c.

◆ TryStripUrlPrefix()

static bool TryStripUrlPrefix ( upb_strview str)
static

Definition at line 1130 of file protobuf/php/ext/google/protobuf/message.c.

◆ ValueEq()

bool ValueEq ( upb_msgval  val1,
upb_msgval  val2,
TypeInfo  type 
)

Variable Documentation

◆ message_ce

zend_class_entry* message_ce

Definition at line 60 of file protobuf/php/ext/google/protobuf/message.c.

◆ Message_methods

zend_function_entry Message_methods[]
static
Initial value:
= {
ZEND_FE_END
}

Definition at line 1089 of file protobuf/php/ext/google/protobuf/message.c.

◆ message_object_handlers

zend_object_handlers message_object_handlers
static

Definition at line 61 of file protobuf/php/ext/google/protobuf/message.c.

◆ TYPE_URL_PREFIX

const char TYPE_URL_PREFIX[] = "type.googleapis.com/"
static

Definition at line 1109 of file protobuf/php/ext/google/protobuf/message.c.



grpc
Author(s):
autogenerated on Fri May 16 2025 03:01:23