NAME
Protobuf::WKT::Any - Mixin for google.protobuf.Any message
VERSION
version 0.03
SYNOPSIS
# In your .proto
import "google/protobuf/any.proto";
message MyMessage {
google.protobuf.Any details = 1;
}
# In your Perl code
my $any = $my_message->details; # Assuming this is an instance of the generated class for Any
# Packing
my $other_msg = Other::Message->new(foo => 'bar');
$any->pack($other_msg);
# Unpacking
if ($any->type_url =~ /Other.Message$/) {
my $unpacked = $any->unpack('Other::Message');
# $unpacked is now an instance of Other::Message
}
DESCRIPTION
This module provides helper methods (pack and unpack) for the generated class corresponding to the google.protobuf.Any Well-Known Type. These methods are injected into the Protobuf::WKT::Any class, which should be automatically used when google/protobuf/any.proto is processed.
The Any type allows embedding a message of any type within it, along with a type URL to identify the embedded message type.
METHODS
pack($msg)
Serializes the given $msg (which must be a Protobuf::Message instance) and stores it in the value field. It also sets the type_url field to type.googleapis.com/ followed by the full name of the message type.
Returns $self for chaining.
unpack($expected_class)
Deserializes the message stored in the value field. It uses the type_url to determine the message type.
If $expected_class is provided, it is used as the Perl class to deserialize into. Otherwise, the class is derived from the type_url and looked up in the generated_pool.
Returns the deserialized message instance.
Dies if the type from type_url cannot be found in the descriptor pool.
get_injected_methods()
Internal method used by the class generator to know which methods to inject. Returns qw(pack unpack).
SEE ALSO
Protobuf, Protobuf::Message, Protobuf::DescriptorPool
AUTHOR
C.J. Collier <cjac@google.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Google LLC.
This is free software; you can redistribute it and/or modify it under the terms of the BSD 3-Clause License.