NAME

Protobuf::Descriptor::Field - Descriptor for a field in a Protocol Buffer message

VERSION

version 0.04

SYNOPSIS

my $pool = Protobuf::DescriptorPool->generated_pool;
my $msg_def = $pool->find_message_by_name('my.package.MyMessage');
my $field_def = $msg_def->find_field_by_name('my_field');

if ($field_def) {
    print "Field Name: ", $field_def->name, "
";
    print "Type: ", $field_def->type, "
";
    print "Label: ", $field_def->label, "
";
    if ($field_def->message_type) {
        print "Message Type: ", $field_def->message_type->full_name, "
";
    }
}

DESCRIPTION

This class represents the descriptor for a single field within a Protocol Buffer message. It provides methods to introspect the field's properties, such as its name, type, label (required, optional, repeated), and number.

Instances of this class are usually obtained from a Protobuf::Descriptor::MessageDef.

METHODS

name()

Returns the name of the field.

full_name()

Returns the fully qualified name of the field.

number()

Returns the tag number of the field.

type()

Returns a string representing the field's type (e.g., 'double', 'int32', 'string', 'message', 'enum').

label()

Returns a string indicating the field's label: 'optional', 'required', or 'repeated'.

is_repeated()

Returns true if the field is a repeated field.

is_map()

Returns true if the field is a map field.

is_required()

Returns true if the field is a required field.

message_type()

If the field's type is 'message', returns the Protobuf::Descriptor::MessageDef for that message type. Otherwise, returns undef.

enum_type()

If the field's type is 'enum', returns the Protobuf::Descriptor::Enum for that enum type. Otherwise, returns undef.

SEE ALSO

Protobuf, Protobuf::DescriptorPool, Protobuf::Descriptor, Protobuf::Descriptor::MessageDef

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.