NAME

Protobuf::DescriptorPool - Manages a collection of Protocol Buffer descriptors

VERSION

version 0.03

SYNOPSIS

use Protobuf::DescriptorPool;

# Get the default pool containing descriptors from generated files
my $pool = Protobuf::DescriptorPool->generated_pool;

# Find a message descriptor
my $message_def = $pool->find_message_by_name('my.package.MyMessage');
if ($message_def) {
    print "Found: ", $message_def->full_name, "
";
}

# Create a new, empty pool
my $custom_pool = Protobuf::DescriptorPool->new;

# Add descriptors from a serialized FileDescriptorProto
my $file_def = $custom_pool->add_serialized_file($binary_file_descriptor);

# Add descriptors from a serialized FileDescriptorSet
my $file_defs = $custom_pool->add_serialized_file_descriptor_set($binary_file_descriptor_set);

DESCRIPTION

Protobuf::DescriptorPool is a container for Protocol Buffer descriptor objects (like message types, field definitions, enum types, etc.). It allows you to load descriptor information, typically from serialized FileDescriptorProto or FileDescriptorSet messages, and then look up specific descriptors by name.

This class wraps the upb_DefPool functionality from the upb library.

Descriptors loaded into a pool are used to understand the structure of serialized messages, enabling parsing, serialization, and dynamic message creation.

METHODS

== Class Methods

generated_pool()

my $pool = Protobuf::DescriptorPool->generated_pool;

Returns a singleton instance of the descriptor pool that contains all the message, enum, and file descriptors that were compiled into your Perl application, typically from .proto files processed by protoc-gen-perl-pb at build time.

== Instance Methods

new()

my $pool = Protobuf::DescriptorPool->new;

Creates a new, empty descriptor pool.

add_serialized_file($serialized_file_descriptor)

my $file_def = $pool->add_serialized_file($binary_data);

Parses a binary string containing a single serialized google.protobuf.FileDescriptorProto message. The descriptors defined within that file are added to the pool. On success, returns the Protobuf::Descriptor::File object for the added file.

Triggers Protobuf::ClassGenerator to define Perl classes for the messages in the file.

add_serialized_file_descriptor_set($serialized_file_descriptor_set)

my $file_defs = $pool->add_serialized_file_descriptor_set($binary_data);

Parses a binary string containing a serialized google.protobuf.FileDescriptorSet message. All files within the set are added to the pool. On success, returns an ArrayRef of Protobuf::Descriptor::File objects.

Triggers Protobuf::ClassGenerator for each file added.

find_file_by_name($name)

my $file_def = $pool->find_file_by_name('path/to/my.proto');

Finds a Protobuf::Descriptor::File by its name (usually the original .proto file path). Returns undef if not found.

find_message_by_name($full_name)

my $msg_def = $pool->find_message_by_name('my.package.MyMessage');

Finds a Protobuf::Descriptor::MessageDef by its fully qualified name. Returns undef if not found.

find_enum_by_name($full_name)

my $enum_def = $pool->find_enum_by_name('my.package.MyEnum');

Finds a Protobuf::Descriptor::Enum by its fully qualified name. Returns undef if not found.

find_extension_by_name($full_name)

my $ext_def = $pool->find_extension_by_name('my.package.my_extension');

Finds a Protobuf::Descriptor::Field representing an extension by its fully qualified name. Returns undef if not found.

freeze()

(Not Yet Implemented) Marks the pool as immutable. Attempting to add more descriptors after freezing will result in an error. This is a prerequisite for potentially sharing pools across threads in the future.

is_frozen()

(Not Yet Implemented) Returns true if the pool has been frozen.

DEMOLISH()

Internal method to clean up the underlying upb_DefPool and its associated arena when the Perl object is destroyed.

CLONE()

Throws an error. Descriptor pools cannot be safely cloned across threads.

SEE ALSO

Protobuf, Protobuf::Descriptor, Protobuf::ClassGenerator

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.