class Serializer (View source)

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 array
decodeAnyMessages(iterable $anyArray)

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

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

static 
loadKnownMetadataTypes()

No description

Details

__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

array encodeMessage(mixed $message)

Encode protobuf message as a PHP array

Parameters

mixed $message

Return Value

array

Exceptions

ValidationException

mixed decodeMessage(mixed $message, array $data)

Decode PHP array into the specified protobuf message

Parameters

mixed $message
array $data

Return Value

mixed

Exceptions

ValidationException

static string serializeToJson(Message $message)

No description

Parameters

Message $message

Return Value

string

Json representation of $message

Exceptions

ValidationException

static array serializeToPhpArray(Message $message)

No description

Parameters

Message $message

Return Value

array

PHP array representation of $message

Exceptions

ValidationException

static array decodeMetadata(array $metadata)

Decode metadata received from gRPC status object

Parameters

array $metadata

Return Value

array

static array decodeAnyMessages(iterable $anyArray)

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

Parameters

iterable $anyArray

Return Value

array

static string getGetter(string $name)

No description

Parameters

string $name

Return Value

string

Getter function

static string getSetter(string $name)

No description

Parameters

string $name

Return Value

string

Setter function

static string toSnakeCase(string $key)

Convert string from camelCase to snake_case

Parameters

string $key

Return Value

string

static string toCamelCase(string $key)

Convert string from snake_case to camelCase

Parameters

string $key

Return Value

string

static loadKnownMetadataTypes()

No description