Copied!

Collection of methods to help with serialization of protobuf objects

CloneableInstantiable
Constants
public Google\ApiCore\Serializer::MAP_KEY_FIELD_NAME = 'key'
public Google\ApiCore\Serializer::MAP_VALUE_FIELD_NAME = 'value'
Methods
public __construct( $fieldTransformers = [], $messageTypeTransformers = [], $decodeFieldTransformers = [], $decodeMessageTypeTransformers = [], $customEncoders = [])
 

Serializer constructor.

  • param array $fieldTransformers An array mapping field names to transformation functions
  • param array $messageTypeTransformers An array mapping message names to transformation functions
  • param array $decodeFieldTransformers An array mapping field names to transformation functions
  • param array $decodeMessageTypeTransformers An array mapping message names to transformation functions
public static decodeAnyMessages( $anyArray)
 

Decode an array of Any messages into a printable PHP array.

  • param iterable $anyArray
  • return array
public decodeMessage( $message, array $data)
 

Decode PHP array into the specified protobuf message

  • param mixed $message
  • param array $data
  • return mixed
  • throws \ValidationException
public static decodeMetadata(array $metadata, ?array $errors = NULL)
 

Decode metadata received from gRPC status object

  • param array $metadata
  • param null|array $errors
  • return array
public encodeMessage( $message)
 

Encode protobuf message as a PHP array

  • param mixed $message
  • return array
  • throws \ValidationException
public static getGetter(string $name)
 
  • param string $name
  • return string Getter function
public static getSetter(string $name)
 
  • param string $name
  • return string Setter function
public static loadKnownMetadataTypes()
public static serializeToJson(Google\Protobuf\Internal\Message $message)
 
  • param \Message $message
  • return string Json representation of $message
  • throws \ValidationException
public static serializeToPhpArray(Google\Protobuf\Internal\Message $message)
 
  • param \Message $message
  • return array PHP array representation of $message
  • throws \ValidationException
public static toCamelCase(string $key)
 

Convert string from snake_case to camelCase

  • param string $key
  • return string
public static toSnakeCase(string $key)
 

Convert string from camelCase to snake_case

  • param string $key
  • return string
Properties
private static array $camelCaseMap = []
private $customEncoders = NULL
private $decodeFieldTransformers = NULL
private $decodeMessageTypeTransformers = NULL
private $descriptorMaps = []
private $fieldTransformers = NULL
private static array $getterMap = []
private $messageTypeTransformers = NULL
private static $phpArraySerializer = NULL
private static array $setterMap = []
private static array $snakeCaseMap = []
Methods
private checkFieldRepeated(Google\Protobuf\FieldDescriptor $field) : bool
 
  • param \FieldDescriptor $field
  • return bool
private decodeElement(Google\Protobuf\FieldDescriptor $field, $data)
 
  • param \FieldDescriptor $field
  • param mixed $data
  • return mixed
  • throws \Exception
private decodeMessageImpl(Google\Protobuf\Internal\Message $message, Google\Protobuf\Descriptor $messageType, array $data)
 
  • param \Message $message
  • param \Descriptor $messageType
  • param array $data
  • return mixed
  • throws \Exception
private encodeElement(Google\Protobuf\FieldDescriptor $field, $data)
 
  • param \FieldDescriptor $field
  • param \Message|array|string $data
  • return mixed
  • throws \Exception
private encodeMessageImpl(Google\Protobuf\Internal\Message $message, Google\Protobuf\Descriptor $messageType)
 
  • param \Message $message
  • param \Descriptor $messageType
  • return array
  • throws \Exception
private getDescriptorMaps(Google\Protobuf\Descriptor $descriptor)
private static getPhpArraySerializer()
private static hasBinaryHeaderSuffix(string $key)
Properties
private static array $camelCaseMap = []
private static array $getterMap = []
private static $phpArraySerializer = NULL
private static array $setterMap = []
private static array $snakeCaseMap = []
Methods
public static decodeAnyMessages( $anyArray)
 

Decode an array of Any messages into a printable PHP array.

  • param iterable $anyArray
  • return array
public static decodeMetadata(array $metadata, ?array $errors = NULL)
 

Decode metadata received from gRPC status object

  • param array $metadata
  • param null|array $errors
  • return array
public static getGetter(string $name)
 
  • param string $name
  • return string Getter function
private static getPhpArraySerializer()
public static getSetter(string $name)
 
  • param string $name
  • return string Setter function
private static hasBinaryHeaderSuffix(string $key)
public static loadKnownMetadataTypes()
public static serializeToJson(Google\Protobuf\Internal\Message $message)
 
  • param \Message $message
  • return string Json representation of $message
  • throws \ValidationException
public static serializeToPhpArray(Google\Protobuf\Internal\Message $message)
 
  • param \Message $message
  • return array PHP array representation of $message
  • throws \ValidationException
public static toCamelCase(string $key)
 

Convert string from snake_case to camelCase

  • param string $key
  • return string
public static toSnakeCase(string $key)
 

Convert string from camelCase to snake_case

  • param string $key
  • return string
© 2026 Bruce Wells
Search Namespaces \ Classes
Configuration