class Serializer

Collection of methods to help with serialization of protobuf objects

Constants

MAP_KEY_FIELD_NAME

MAP_VALUE_FIELD_NAME

Methods

__construct(array $fieldTransformers = [], array $messageTypeTransformers = [], array $decodeFieldTransformers = [], array $decodeMessageTypeTransformers = [])

Serializer constructor.

array
encodeMessage(mixed $message)

Encode protobuf message as a PHP array

mixed
decodeMessage(mixed $message, array $data)

Decode PHP array into the specified protobuf message

static string
serializeToJson(Message $message)

No description

static array
serializeToPhpArray(Message $message)

No description

static array
decodeMetadata(array $metadata)

Decode metadata received from gRPC status object

static string
getGetter(string $name)

No description

static string
getSetter(string $name)

No description

static string
toSnakeCase(string $key)

Convert string from camelCase to snake_case

static string
toCamelCase(string $key)

Convert string from snake_case to camelCase

Details

at line 75
__construct(array $fieldTransformers = [], array $messageTypeTransformers = [], array $decodeFieldTransformers = [], array $decodeMessageTypeTransformers = [])

Serializer constructor.

Parameters

array $fieldTransformers An array mapping field names to transformation functions
array $messageTypeTransformers An array mapping message names to transformation functions
array $decodeFieldTransformers An array mapping field names to transformation functions
array $decodeMessageTypeTransformers An array mapping message names to transformation functions

at line 93
array encodeMessage(mixed $message)

Encode protobuf message as a PHP array

Parameters

mixed $message

Return Value

array

at line 108
mixed decodeMessage(mixed $message, array $data)

Decode PHP array into the specified protobuf message

Parameters

mixed $message
array $data

Return Value

mixed

at line 120
static string serializeToJson(Message $message)

Parameters

Message $message

Return Value

string Json representation of $message

at line 129
static array serializeToPhpArray(Message $message)

Parameters

Message $message

Return Value

array PHP array representation of $message

at line 140
static array decodeMetadata(array $metadata)

Decode metadata received from gRPC status object

Parameters

array $metadata

Return Value

array

at line 355
static string getGetter(string $name)

Parameters

string $name

Return Value

string Getter function

at line 364
static string getSetter(string $name)

Parameters

string $name

Return Value

string Setter function

at line 375
static string toSnakeCase(string $key)

Convert string from camelCase to snake_case

Parameters

string $key

Return Value

string

at line 386
static string toCamelCase(string $key)

Convert string from snake_case to camelCase

Parameters

string $key

Return Value

string