Class DynamicMessage (3.19.4)

publicfinalclassDynamicMessageextendsAbstractMessage

An implementation ofMessage that can represent arbitrary types, given aDescriptors.Descriptor.

Inherited Members

Static Methods

getDefaultInstance(Descriptors.Descriptor type)

publicstaticDynamicMessagegetDefaultInstance(Descriptors.Descriptortype)

Get aDynamicMessage representing the default instance of the given type.

Parameter
NameDescription
typeDescriptors.Descriptor
Returns
TypeDescription
DynamicMessage

newBuilder(Descriptors.Descriptor type)

publicstaticDynamicMessage.BuildernewBuilder(Descriptors.Descriptortype)

Construct aMessage.Builder for the given type.

Parameter
NameDescription
typeDescriptors.Descriptor
Returns
TypeDescription
DynamicMessage.Builder

newBuilder(Message prototype)

publicstaticDynamicMessage.BuildernewBuilder(Messageprototype)

Construct aMessage.Builder for a message of the same type asprototype, and initialize it withprototype's contents.

Parameter
NameDescription
prototypeMessage
Returns
TypeDescription
DynamicMessage.Builder

parseFrom(Descriptors.Descriptor type, byte[] data)

publicstaticDynamicMessageparseFrom(Descriptors.Descriptortype,byte[]data)

Parsedata as a message of the given type and return it.

Parameters
NameDescription
typeDescriptors.Descriptor
databyte[]
Returns
TypeDescription
DynamicMessage
Exceptions
TypeDescription
InvalidProtocolBufferException

parseFrom(Descriptors.Descriptor type, byte[] data, ExtensionRegistry extensionRegistry)

publicstaticDynamicMessageparseFrom(Descriptors.Descriptortype,byte[]data,ExtensionRegistryextensionRegistry)

Parsedata as a message of the given type and return it.

Parameters
NameDescription
typeDescriptors.Descriptor
databyte[]
extensionRegistryExtensionRegistry
Returns
TypeDescription
DynamicMessage
Exceptions
TypeDescription
InvalidProtocolBufferException

parseFrom(Descriptors.Descriptor type, ByteString data)

publicstaticDynamicMessageparseFrom(Descriptors.Descriptortype,ByteStringdata)

Parsedata as a message of the given type and return it.

Parameters
NameDescription
typeDescriptors.Descriptor
dataByteString
Returns
TypeDescription
DynamicMessage
Exceptions
TypeDescription
InvalidProtocolBufferException

parseFrom(Descriptors.Descriptor type, ByteString data, ExtensionRegistry extensionRegistry)

publicstaticDynamicMessageparseFrom(Descriptors.Descriptortype,ByteStringdata,ExtensionRegistryextensionRegistry)

Parsedata as a message of the given type and return it.

Parameters
NameDescription
typeDescriptors.Descriptor
dataByteString
extensionRegistryExtensionRegistry
Returns
TypeDescription
DynamicMessage
Exceptions
TypeDescription
InvalidProtocolBufferException

parseFrom(Descriptors.Descriptor type, CodedInputStream input)

publicstaticDynamicMessageparseFrom(Descriptors.Descriptortype,CodedInputStreaminput)

Parse a message of the given type from the given input stream.

Parameters
NameDescription
typeDescriptors.Descriptor
inputCodedInputStream
Returns
TypeDescription
DynamicMessage
Exceptions
TypeDescription
IOException

parseFrom(Descriptors.Descriptor type, CodedInputStream input, ExtensionRegistry extensionRegistry)

publicstaticDynamicMessageparseFrom(Descriptors.Descriptortype,CodedInputStreaminput,ExtensionRegistryextensionRegistry)

Parse a message of the given type from the given input stream.

Parameters
NameDescription
typeDescriptors.Descriptor
inputCodedInputStream
extensionRegistryExtensionRegistry
Returns
TypeDescription
DynamicMessage
Exceptions
TypeDescription
IOException

parseFrom(Descriptors.Descriptor type, InputStream input)

publicstaticDynamicMessageparseFrom(Descriptors.Descriptortype,InputStreaminput)

Parse a message of the given type frominput and return it.

Parameters
NameDescription
typeDescriptors.Descriptor
inputInputStream
Returns
TypeDescription
DynamicMessage
Exceptions
TypeDescription
IOException

parseFrom(Descriptors.Descriptor type, InputStream input, ExtensionRegistry extensionRegistry)

publicstaticDynamicMessageparseFrom(Descriptors.Descriptortype,InputStreaminput,ExtensionRegistryextensionRegistry)

Parse a message of the given type frominput and return it.

Parameters
NameDescription
typeDescriptors.Descriptor
inputInputStream
extensionRegistryExtensionRegistry
Returns
TypeDescription
DynamicMessage
Exceptions
TypeDescription
IOException

Methods

getAllFields()

publicMap<Descriptors.FieldDescriptor,Object>getAllFields()
Returns
TypeDescription
Map<FieldDescriptor,Object>

getDefaultInstanceForType()

publicDynamicMessagegetDefaultInstanceForType()
Returns
TypeDescription
DynamicMessage

getDescriptorForType()

publicDescriptors.DescriptorgetDescriptorForType()
Returns
TypeDescription
Descriptors.Descriptor

getField(Descriptors.FieldDescriptor field)

publicObjectgetField(Descriptors.FieldDescriptorfield)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
Object

getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)

publicDescriptors.FieldDescriptorgetOneofFieldDescriptor(Descriptors.OneofDescriptoroneof)

TODO(jieluo): Clear it when all subclasses have implemented this method.

Parameter
NameDescription
oneofDescriptors.OneofDescriptor
Returns
TypeDescription
Descriptors.FieldDescriptor
Overrides

getParserForType()

publicParser<DynamicMessage>getParserForType()
Returns
TypeDescription
Parser<DynamicMessage>

getRepeatedField(Descriptors.FieldDescriptor field, int index)

publicObjectgetRepeatedField(Descriptors.FieldDescriptorfield,intindex)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
indexint
Returns
TypeDescription
Object

getRepeatedFieldCount(Descriptors.FieldDescriptor field)

publicintgetRepeatedFieldCount(Descriptors.FieldDescriptorfield)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
int

getSerializedSize()

publicintgetSerializedSize()

Get the number of bytes required to encode this message. The result is only computed on the first call and memoized after that.

If this message requires more than Integer.MAX_VALUE bytes to encode, the return value will be smaller than the actual number of bytes required and might be negative.

Returns
TypeDescription
int
Overrides

getUnknownFields()

publicUnknownFieldSetgetUnknownFields()
Returns
TypeDescription
UnknownFieldSet

hasField(Descriptors.FieldDescriptor field)

publicbooleanhasField(Descriptors.FieldDescriptorfield)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
boolean

hasOneof(Descriptors.OneofDescriptor oneof)

publicbooleanhasOneof(Descriptors.OneofDescriptoroneof)

TODO(jieluo): Clear it when all subclasses have implemented this method.

Parameter
NameDescription
oneofDescriptors.OneofDescriptor
Returns
TypeDescription
boolean
Overrides

isInitialized()

publicbooleanisInitialized()

Returns true if all required fields in the message and all embedded messages are set, false otherwise.

See also:MessageOrBuilder#getInitializationErrorString()

Returns
TypeDescription
boolean
Overrides

newBuilderForType()

publicDynamicMessage.BuildernewBuilderForType()
Returns
TypeDescription
DynamicMessage.Builder

toBuilder()

publicDynamicMessage.BuildertoBuilder()
Returns
TypeDescription
DynamicMessage.Builder

writeTo(CodedOutputStream output)

publicvoidwriteTo(CodedOutputStreamoutput)

Serializes the message and writes it tooutput. This does not flush or close the stream.

Parameter
NameDescription
outputCodedOutputStream
Overrides
Exceptions
TypeDescription
IOException

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.