descriptor.proto source code

34 views
Skip to first unread message

Wells Cool

unread,
Jul 4, 2024, 12:13:17 PMJul 4
to Protocol Buffers
message DescriptorProto {
  optional string name = 1;

  repeated FieldDescriptorProto field = 2;
  repeated FieldDescriptorProto extension = 6;

  repeated DescriptorProto nested_type = 3;
  repeated EnumDescriptorProto enum_type = 4;

  message ExtensionRange {
    optional int32 start = 1;  // Inclusive.
    optional int32 end = 2;    // Exclusive.

    optional ExtensionRangeOptions options = 3;
  }
  repeated ExtensionRange extension_range = 5;

  repeated OneofDescriptorProto oneof_decl = 8;

  optional MessageOptions options = 7;

  // Range of reserved tag numbers. Reserved tag numbers may not be used by
  // fields or extension ranges in the same message. Reserved ranges may
  // not overlap.
  message ReservedRange {
    optional int32 start = 1;  // Inclusive.
    optional int32 end = 2;    // Exclusive.
  }
  repeated ReservedRange reserved_range = 9;
  // Reserved field names, which may not be used by fields in the same message.
  // A given name may only be reserved once.
  repeated string reserved_name = 10;
}

Hi! Why is it permissible to recursively define repeated DescriptorProto nested_type = 3; inside the message DescriptorProto?  Thanks!

Derek Perez

unread,
Jul 8, 2024, 4:58:25 AM (11 days ago) Jul 8
to Wells Cool, Protocol Buffers
Protobuf messages can recursively reference themselves to create nested structures. It's permissible because the language allows you to reference the type once it's been defined, including within its own definition.

I hope that helps!
- Derek

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/bb9da598-429d-4bfa-ac79-d4e6b7fc3b16n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages