class documentation

Each of the definitions above may have "options" attached. These are just annotations which may cause code to be generated slightly differently or may contain hints for code that manipulates protocol messages.

Clients may define custom options as extensions of the *Options messages. These extensions may not yet be known at parsing time, so the parser cannot store the values in them. Instead it stores them in a field in the *Options message called uninterpreted_option. This field must have the same name across all *Options messages. We then use this field to populate the extensions when we build a descriptor, at which point all protos have been parsed and so all extensions are known.

Extension numbers for custom options may be chosen as follows:

  • For options which will only be used within a single application or organization, or for experimental options, use field numbers 50000 through 99999. It is up to you to ensure that you do not use the same number for multiple options.

  • For options which will be published and used publicly by multiple independent entities, e-mail protobuf-global-extension-registry@google.com to reserve extension numbers. Simply provide your project name (e.g. Objective-C plugin) and your project website (if available) -- there's no need to explain how you intend to use them. Usually you only need one extension number. You can declare multiple options with only one extension number by putting them in a sub-message. See the Custom Options section of the docs for examples:

    https://developers.google.com/protocol-buffers/docs/proto#options If this turns out to be popular, a web service will be set up to automatically assign option numbers.

Class OptimizeMode Generated classes can be optimized for speed or code size.
Method __init__ Create a message from a source message and field values.
Method cc_enable_arenas.setter Set or clear the generated cc_enable_arenas field.
Method cc_generic_services.setter Set or clear the generated cc_generic_services field.
Method csharp_namespace.setter Set or clear the generated csharp_namespace field.
Method deprecated.setter Set or clear the generated deprecated field.
Method features.setter Set or clear the generated features field.
Method go_package.setter Set or clear the generated go_package field.
Method java_generate_equals_and_hash.setter Set or clear the generated java_generate_equals_and_hash field.
Method java_generic_services.setter Set or clear the generated java_generic_services field.
Method java_multiple_files.setter Set or clear the generated java_multiple_files field.
Method java_outer_classname.setter Set or clear the generated java_outer_classname field.
Method java_package.setter Set or clear the generated java_package field.
Method java_string_check_utf8.setter Set or clear the generated java_string_check_utf8 field.
Method objc_class_prefix.setter Set or clear the generated objc_class_prefix field.
Method optimize_for.setter Set or clear the generated optimize_for field.
Method php_class_prefix.setter Set or clear the generated php_class_prefix field.
Method php_metadata_namespace.setter Set or clear the generated php_metadata_namespace field.
Method php_namespace.setter Set or clear the generated php_namespace field.
Method py_generic_services.setter Set or clear the generated py_generic_services field.
Method ruby_package.setter Set or clear the generated ruby_package field.
Method swift_prefix.setter Set or clear the generated swift_prefix field.
Method uninterpreted_option.setter Set or clear the generated uninterpreted_option field.
Property cc_enable_arenas Enables the use of arenas for the proto messages in this file. This applies only to generated classes for C++.
Property cc_generic_services Should generic services be generated in each language? "Generic" services are not specific to any particular RPC system. They are generated by the main code generators in each language (without additional plugins)...
Property csharp_namespace Namespace for generated classes; defaults to the package.
Property deprecated Is this file deprecated? Depending on the target platform, this can emit Deprecated annotations for everything in the file, or it will be completely ignored; in the very least, this is a formalization for deprecating files.
Property features Any features defined in the specific edition. WARNING: This field should only be used by protobuf plugins or special cases like the proto compiler. Other uses are discouraged and developers should rely on the protoreflect APIs for their client language.
Property go_package Sets the Go package where structs generated from this .proto will be placed. If omitted, the Go package will be derived from the following:
Property java_generate_equals_and_hash This option does nothing.
Property java_generic_services Undocumented
Property java_multiple_files If enabled, then the Java code generator will generate a separate .java file for each top-level message, enum, and service defined in the .proto file. Thus, these types will not be nested inside the wrapper class named by java_outer_classname...
Property java_outer_classname Controls the name of the wrapper Java class generated for the .proto file. That class will always contain the .proto file's getDescriptor() method as well as any top-level extensions defined in the .proto file...
Property java_package Sets the Java package where classes generated from this .proto will be placed. By default, the proto package is used, but this is often inappropriate because proto packages do not normally start with backwards domain names.
Property java_string_check_utf8 A proto2 file can set this to true to opt in to UTF-8 checking for Java, which will throw an exception if invalid UTF-8 is parsed from the wire or assigned to a string field.
Property objc_class_prefix Sets the objective c class prefix which is prepended to all objective c generated classes from this .proto. There is no default.
Property optimize_for Undocumented
Property php_class_prefix Sets the php class prefix which is prepended to all php generated classes from this .proto. Default is empty.
Property php_metadata_namespace Use this option to change the namespace of php generated metadata classes. Default is empty. When this option is empty, the proto file name will be used for determining the namespace.
Property php_namespace Use this option to change the namespace of php generated classes. Default is empty. When this option is empty, the package name will be used for determining the namespace.
Property py_generic_services Undocumented
Property ruby_package Use this option to change the package of ruby generated classes. Default is empty. When this option is not set, the package name will be used for determining the ruby package.
Property swift_prefix By default Swift generators will take the proto package and CamelCase it replacing '.' with underscore and use that to prefix the types/symbols defined. When this options is provided, they will use this value instead to prefix the types/symbols defined.
Property uninterpreted_option The parser stores options it doesn't recognize here. See the documentation for the "Options" section above.

Inherited from Message:

Class Method from_json Create a message from protobuf JSON mapping.
Class Method FromString Create a message by parsing protobuf wire-format bytes.
Class Method get_descriptor Return the message descriptor from the registry.
Class Method is_credentials Return True if a Python field contains credentials.
Class Method is_sensitive Return True if a Python field has the sensitive annotation.
Method __dir__ List generated fields, oneofs, and nested declarations.
Method __repr__ Render non-default fields without disclosing annotated secrets.
Method ByteSize Return the serialized protobuf wire size in bytes.
Method check_presence Check presence using a generated Python field name.
Method Clear Clear all fields, extensions, unknown fields, and the reset mask.
Method clear_extension Clear an extension value.
Method ClearField Clear a protobuf field or oneof and record it in the reset mask.
Method CopyFrom Replace this message with an independent copy of another message.
Method FindInitializationErrors Return paths of missing required fields.
Method get_extension Return an extension value.
Method get_full_update_reset_mask Create a reset mask from the current protobuf state.
Method get_mask Return the reset mask for field changes.
Method has_extension Return True if an extension has explicit presence.
Method HasField Return True if a protobuf field or oneof has explicit presence.
Method is_default Return True if a generated field has its default value.
Method IsInitialized Return True if every required field is initialized.
Method MergeFrom Merge fields from another message of the same generated type.
Method MergeFromString Merge protobuf wire-format bytes into this message.
Method ParseFromString Parse protobuf wire-format bytes and replace this message.
Method SerializeToString Serialize the message using protobuf wire format.
Method set_extension Set an extension value.
Method set_mask Set the reset mask for this message.
Method to_json Serialize this message using protobuf JSON mapping.
Method which_field_in_oneof Return the selected Python field name for a protobuf oneof.
Method WhichOneof Return the selected protobuf field name for a oneof.
Constant __DEPRECATION_DETAILS__ Undocumented
Constant __EXTENSION_REGISTRY__ Registry that decodes protobuf extensions.
Constant __FIELDS__ Runtime field data that the generator creates.
Constant __MAX_NESTING_DEPTH__ Maximum protobuf nesting depth for serialization, parsing, and initialization checks.
Constant __PB2_DESCRIPTOR__ Alias for code that expects a protobuf descriptor.
Constant __PROTO_DESCRIPTOR__ Message descriptor from the registry.
Constant __PY_TO_PB2__ Mapping from Python names to protobuf names.
Constant __REGISTRY__ Registry for the message and its descriptor.
Class Variable __PROTO_FULL_NAME__ Fully qualified protobuf message name.
Property Extensions Provide protobuf-compatible mapping access to extension values.
Class Method _fields_by_number Undocumented
Class Method _fields_by_proto_name Undocumented
Class Method _fields_by_python_name Undocumented
Class Method _from_string Deserialize internally without invoking generated user warnings.
Class Method _oneof_python_name Undocumented
Class Method _public_fields_by_proto_name Undocumented
Class Method _public_fields_by_python_name Undocumented
Static Method _format_map_key Undocumented
Static Method _repr_field Undocumented
Method _bind_child Undocumented
Method _bind_mutation Undocumented
Method _check_same_type Undocumented
Method _child_changed Undocumented
Method _clear_state Undocumented
Method _closed_enum_unknown Undocumented
Method _converted_view Undocumented
Method _decode_map_entry Undocumented
Method _detach_child Undocumented
Method _field_has_value Undocumented
Method _field_is_default Undocumented
Method _find_initialization_errors Undocumented
Method _get_field Undocumented
Method _initialize Initialize message state, optionally suppressing generated warnings.
Method _map Undocumented
Method _merge_from_string Undocumented
Method _nesting_limit Undocumented
Method _notify Undocumented
Method _record_reset Undocumented
Method _repeated Undocumented
Method _select Undocumented
Method _serialize_to_string Undocumented
Method _set_field Undocumented
Method _suspend_mutation Undocumented
Method _suspend_reset_mask Undocumented
Method _try_decode_field Undocumented
Method _write_field Undocumented
Instance Variable _extensions Undocumented
Instance Variable _mutation_suspended Undocumented
Instance Variable _on_mutation Undocumented
Instance Variable _oneofs Undocumented
Instance Variable _present Undocumented
Instance Variable _reset_mask Undocumented
Instance Variable _reset_mask_suspended Undocumented
Instance Variable _unknown_fields Undocumented
Instance Variable _values Undocumented
Instance Variable _views Undocumented
def __init__(self, initial_message: SerializableMessage | None = None, *, java_package: str | None | UnsetType = ..., java_outer_classname: str | None | UnsetType = ..., java_multiple_files: bool | None | UnsetType = ..., java_generate_equals_and_hash: bool | None | UnsetType = ..., java_string_check_utf8: bool | None | UnsetType = ..., optimize_for: OptimizeMode | None | UnsetType = ..., go_package: str | None | UnsetType = ..., cc_generic_services: bool | None | UnsetType = ..., java_generic_services: bool | None | UnsetType = ..., py_generic_services: bool | None | UnsetType = ..., deprecated: bool | None | UnsetType = ..., cc_enable_arenas: bool | None | UnsetType = ..., objc_class_prefix: str | None | UnsetType = ..., csharp_namespace: str | None | UnsetType = ..., swift_prefix: str | None | UnsetType = ..., php_class_prefix: str | None | UnsetType = ..., php_namespace: str | None | UnsetType = ..., php_metadata_namespace: str | None | UnsetType = ..., ruby_package: str | None | UnsetType = ..., features: FeatureSet | None | UnsetType = ..., uninterpreted_option: Iterable[UninterpretedOption] | None | UnsetType = ...): (source)

Create a message from a source message and field values.

@cc_enable_arenas.setter
def cc_enable_arenas(self, value: bool | None): (source)

Set or clear the generated cc_enable_arenas field.

@cc_generic_services.setter
def cc_generic_services(self, value: bool | None): (source)

Set or clear the generated cc_generic_services field.

@csharp_namespace.setter
def csharp_namespace(self, value: str | None): (source)

Set or clear the generated csharp_namespace field.

@deprecated.setter
def deprecated(self, value: bool | None): (source)

Set or clear the generated deprecated field.

@features.setter
def features(self, value: FeatureSet | None): (source)

Set or clear the generated features field.

@go_package.setter
def go_package(self, value: str | None): (source)

Set or clear the generated go_package field.

@java_generate_equals_and_hash.setter
def java_generate_equals_and_hash(self, value: bool | None): (source)

Set or clear the generated java_generate_equals_and_hash field.

@java_generic_services.setter
def java_generic_services(self, value: bool | None): (source)

Set or clear the generated java_generic_services field.

@java_multiple_files.setter
def java_multiple_files(self, value: bool | None): (source)

Set or clear the generated java_multiple_files field.

@java_outer_classname.setter
def java_outer_classname(self, value: str | None): (source)

Set or clear the generated java_outer_classname field.

@java_package.setter
def java_package(self, value: str | None): (source)

Set or clear the generated java_package field.

@java_string_check_utf8.setter
def java_string_check_utf8(self, value: bool | None): (source)

Set or clear the generated java_string_check_utf8 field.

@objc_class_prefix.setter
def objc_class_prefix(self, value: str | None): (source)

Set or clear the generated objc_class_prefix field.

@optimize_for.setter
def optimize_for(self, value: OptimizeMode | None): (source)

Set or clear the generated optimize_for field.

@php_class_prefix.setter
def php_class_prefix(self, value: str | None): (source)

Set or clear the generated php_class_prefix field.

@php_metadata_namespace.setter
def php_metadata_namespace(self, value: str | None): (source)

Set or clear the generated php_metadata_namespace field.

@php_namespace.setter
def php_namespace(self, value: str | None): (source)

Set or clear the generated php_namespace field.

@py_generic_services.setter
def py_generic_services(self, value: bool | None): (source)

Set or clear the generated py_generic_services field.

@ruby_package.setter
def ruby_package(self, value: str | None): (source)

Set or clear the generated ruby_package field.

@swift_prefix.setter
def swift_prefix(self, value: str | None): (source)

Set or clear the generated swift_prefix field.

Set or clear the generated uninterpreted_option field.

@property
cc_enable_arenas: bool = (source)

Enables the use of arenas for the proto messages in this file. This applies only to generated classes for C++.

@property
cc_generic_services: bool = (source)

Should generic services be generated in each language? "Generic" services are not specific to any particular RPC system. They are generated by the main code generators in each language (without additional plugins). Generic services were the only kind of service generation supported by early versions of google.protobuf.

Generic services are now considered deprecated in favor of using plugins that generate code specific to your particular RPC system. Therefore, these default to false. Old code which depends on generic services should explicitly set them to true.

@property
csharp_namespace: str = (source)

Namespace for generated classes; defaults to the package.

Is this file deprecated? Depending on the target platform, this can emit Deprecated annotations for everything in the file, or it will be completely ignored; in the very least, this is a formalization for deprecating files.

Any features defined in the specific edition. WARNING: This field should only be used by protobuf plugins or special cases like the proto compiler. Other uses are discouraged and developers should rely on the protoreflect APIs for their client language.

Sets the Go package where structs generated from this .proto will be placed. If omitted, the Go package will be derived from the following:

  • The basename of the package import path, if provided.
  • Otherwise, the package statement in the .proto file, if present.
  • Otherwise, the basename of the .proto file, without extension.
@property
java_generate_equals_and_hash: bool = (source)

This option does nothing.

Deprecated.

@property
java_generic_services: bool = (source)

Undocumented

@property
java_multiple_files: bool = (source)

If enabled, then the Java code generator will generate a separate .java file for each top-level message, enum, and service defined in the .proto file. Thus, these types will not be nested inside the wrapper class named by java_outer_classname. However, the wrapper class will still be generated to contain the file's getDescriptor() method as well as any top-level extensions defined in the file.

@property
java_outer_classname: str = (source)

Controls the name of the wrapper Java class generated for the .proto file. That class will always contain the .proto file's getDescriptor() method as well as any top-level extensions defined in the .proto file. If java_multiple_files is disabled, then all the other classes from the .proto file will be nested inside the single wrapper outer class.

@property
java_package: str = (source)

Sets the Java package where classes generated from this .proto will be placed. By default, the proto package is used, but this is often inappropriate because proto packages do not normally start with backwards domain names.

@property
java_string_check_utf8: bool = (source)

A proto2 file can set this to true to opt in to UTF-8 checking for Java, which will throw an exception if invalid UTF-8 is parsed from the wire or assigned to a string field.

applies to, and update these docs accordingly.

Proto3 files already perform these checks. Setting the option explicitly to false has no effect: it cannot be used to opt proto3 files out of UTF-8 checks.

@property
objc_class_prefix: str = (source)

Sets the objective c class prefix which is prepended to all objective c generated classes from this .proto. There is no default.

Undocumented

@property
php_class_prefix: str = (source)

Sets the php class prefix which is prepended to all php generated classes from this .proto. Default is empty.

@property
php_metadata_namespace: str = (source)

Use this option to change the namespace of php generated metadata classes. Default is empty. When this option is empty, the proto file name will be used for determining the namespace.

@property
php_namespace: str = (source)

Use this option to change the namespace of php generated classes. Default is empty. When this option is empty, the package name will be used for determining the namespace.

@property
py_generic_services: bool = (source)

Undocumented

@property
ruby_package: str = (source)

Use this option to change the package of ruby generated classes. Default is empty. When this option is not set, the package name will be used for determining the ruby package.

@property
swift_prefix: str = (source)

By default Swift generators will take the proto package and CamelCase it replacing '.' with underscore and use that to prefix the types/symbols defined. When this options is provided, they will use this value instead to prefix the types/symbols defined.

The parser stores options it doesn't recognize here. See the documentation for the "Options" section above.