Send feedback
Class GeneratedMessage (3.19.4)
bookmark_border bookmark
Stay organized with collections
Save and categorize content based on your preferences.
On this page Inheritance Implements Inherited Members Static Fields Static Methods <ContainingType,Type>newFileScopedGeneratedExtension(Class singularType, Message defaultInstance) <ContainingType,Type>newFileScopedGeneratedExtension(Class singularType, Message defaultInstance, String descriptorOuterClass, String extensionName) <ContainingType,Type>newMessageScopedGeneratedExtension(Message scope, int descriptorIndex, Class singularType, Message defaultInstance) <ContainingType,Type>newMessageScopedGeneratedExtension(Message scope, String name, Class singularType, Message defaultInstance) <M>parseDelimitedWithIOException(Parser<M> parser, InputStream input) <M>parseDelimitedWithIOException(Parser<M> parser, InputStream input, ExtensionRegistryLite extensions) <M>parseWithIOException(Parser<M> parser, CodedInputStream input) <M>parseWithIOException(Parser<M> parser, CodedInputStream input, ExtensionRegistryLite extensions) <M>parseWithIOException(Parser<M> parser, InputStream input) <M>parseWithIOException(Parser<M> parser, InputStream input, ExtensionRegistryLite extensions) computeStringSize(int fieldNumber, Object value) computeStringSizeNoTag(Object value) writeString(CodedOutputStream output, int fieldNumber, Object value) writeStringNoTag(CodedOutputStream output, Object value) Constructors Fields Methods
public abstract class GeneratedMessage extends AbstractMessage implements Serializable
All generated protocol message classes extend this class. This class
implements most of the Message and Builder interfaces using Java reflection.
Users can ignore this class and pretend that generated messages implement
the Message interface directly.
Inherited Members
Static Fields
alwaysUseFieldBuilders
protected static boolean alwaysUseFieldBuilders
For testing. Allows a test to disable the optimization that avoids using
field builders for nested messages until they are requested. By disabling
this optimization, existing tests can be reused to test the field builders.
Field Value
Type
Description
boolean
Static Methods
<ContainingType,Type>newFileScopedGeneratedExtension(Class singularType, Message defaultInstance)
public static GeneratedMessage . GeneratedExtension<ContainingType , Type > <ContainingType , Type>newFileScopedGeneratedExtension ( Class singularType , Message defaultInstance )
For use by generated code only.
Parameters
Name
Description
singularType
Class
defaultInstance
Message
<ContainingType,Type>newFileScopedGeneratedExtension(Class singularType, Message defaultInstance, String descriptorOuterClass, String extensionName)
public static GeneratedMessage . GeneratedExtension<ContainingType , Type > <ContainingType , Type>newFileScopedGeneratedExtension ( Class singularType , Message defaultInstance , String descriptorOuterClass , String extensionName )
Used in proto1 generated code only.
After enabling bridge, we can define proto2 extensions (the extended type
is a proto2 mutable message) in a proto1 .proto file. For these extensions
we should generate proto2 GeneratedExtensions.
<ContainingType,Type>newMessageScopedGeneratedExtension(Message scope, int descriptorIndex, Class singularType, Message defaultInstance)
public static GeneratedMessage . GeneratedExtension<ContainingType , Type > <ContainingType , Type>newMessageScopedGeneratedExtension ( Message scope , int descriptorIndex , Class singularType , Message defaultInstance )
For use by generated code only.
<ContainingType,Type>newMessageScopedGeneratedExtension(Message scope, String name, Class singularType, Message defaultInstance)
public static GeneratedMessage . GeneratedExtension<ContainingType , Type > <ContainingType , Type>newMessageScopedGeneratedExtension ( Message scope , String name , Class singularType , Message defaultInstance )
Used in proto1 generated code only.
After enabling bridge, we can define proto2 extensions (the extended type
is a proto2 mutable message) in a proto1 .proto file. For these extensions
we should generate proto2 GeneratedExtensions.
protected static M <M>parseDelimitedWithIOException ( Parser<M> parser , InputStream input )
Returns
Type
Description
M
protected static M <M>parseDelimitedWithIOException ( Parser<M> parser , InputStream input , ExtensionRegistryLite extensions )
Returns
Type
Description
M
protected static M <M>parseWithIOException ( Parser<M> parser , CodedInputStream input )
Returns
Type
Description
M
protected static M <M>parseWithIOException ( Parser<M> parser , CodedInputStream input , ExtensionRegistryLite extensions )
Returns
Type
Description
M
protected static M <M>parseWithIOException ( Parser<M> parser , InputStream input )
Returns
Type
Description
M
protected static M <M>parseWithIOException ( Parser<M> parser , InputStream input , ExtensionRegistryLite extensions )
Returns
Type
Description
M
computeStringSize(int fieldNumber, Object value)
protected static int computeStringSize ( int fieldNumber , Object value )
Parameters
Name
Description
fieldNumber
int
value
Object
Returns
Type
Description
int
computeStringSizeNoTag(Object value)
protected static int computeStringSizeNoTag ( Object value )
Parameter
Name
Description
value
Object
Returns
Type
Description
int
writeString(CodedOutputStream output, int fieldNumber, Object value)
protected static void writeString ( CodedOutputStream output , int fieldNumber , Object value )
writeStringNoTag(CodedOutputStream output, Object value)
protected static void writeStringNoTag ( CodedOutputStream output , Object value )
Constructors
GeneratedMessage()
protected GeneratedMessage ()
GeneratedMessage(GeneratedMessage.Builder<?> builder)
protected GeneratedMessage ( GeneratedMessage . Builder <? > builder )
Parameter
Name
Description
builder
Builder <? >
Fields
unknownFields
protected UnknownFieldSet unknownFields
For use by generated code only.
Methods
getAllFields()
public Map<Descriptors . FieldDescriptor , Object > getAllFields ()
getDescriptorForType()
public Descriptors . Descriptor getDescriptorForType ()
getField(Descriptors.FieldDescriptor field)
public Object getField ( Descriptors . FieldDescriptor field )
Returns
Type
Description
Object
getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)
public Descriptors . FieldDescriptor getOneofFieldDescriptor ( Descriptors . OneofDescriptor oneof )
TODO(jieluo): Clear it when all subclasses have implemented this method.
Overrides
getParserForType()
public Parser <? extends GeneratedMessage > getParserForType ()
Returns
Type
Description
Parser <? extends com.google.protobuf.GeneratedMessage >
getRepeatedField(Descriptors.FieldDescriptor field, int index)
public Object getRepeatedField ( Descriptors . FieldDescriptor field , int index )
Returns
Type
Description
Object
getRepeatedFieldCount(Descriptors.FieldDescriptor field)
public int getRepeatedFieldCount ( Descriptors . FieldDescriptor field )
Returns
Type
Description
int
getSerializedSize()
public int getSerializedSize ()
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
Type
Description
int
Overrides
getUnknownFields()
public UnknownFieldSet getUnknownFields ()
hasField(Descriptors.FieldDescriptor field)
public boolean hasField ( Descriptors . FieldDescriptor field )
hasOneof(Descriptors.OneofDescriptor oneof)
public boolean hasOneof ( Descriptors . OneofDescriptor oneof )
TODO(jieluo): Clear it when all subclasses have implemented this method.
Overrides
internalGetFieldAccessorTable()
protected abstract GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ()
Get the FieldAccessorTable for this type. We can't have the message
class pass this in to the constructor because of bootstrapping trouble
with DescriptorProtos.
internalGetMapField(int fieldNumber)
protected MapField internalGetMapField ( int fieldNumber )
Gets the map field with the given field number. This method should be
overridden in the generated message class if the message contains map
fields.
Unlike other field types, reflection support for map fields can't be
implemented based on generated public API because we need to access a
map field as a list in reflection API but the generated API only allows
us to access it as a map. This method returns the underlying map field
directly and thus enables us to access the map field as a list.
Parameter
Name
Description
fieldNumber
int
isInitialized()
public boolean isInitialized ()
Overrides
makeExtensionsImmutable()
protected void makeExtensionsImmutable ()
Used by parsing constructors in generated classes.
newBuilderForType(AbstractMessage.BuilderParent parent)
protected Message . Builder newBuilderForType ( AbstractMessage . BuilderParent parent )
Overrides
newBuilderForType(GeneratedMessage.BuilderParent parent)
protected abstract Message . Builder newBuilderForType ( GeneratedMessage . BuilderParent parent )
TODO(xiaofeng): remove this together with GeneratedMessage.BuilderParent.
protected boolean parseUnknownField ( CodedInputStream input , UnknownFieldSet . Builder unknownFields , ExtensionRegistryLite extensionRegistry , int tag )
Called by subclasses to parse an unknown field.
Returns
Type
Description
boolean
true
unless the tag is an end-group tag.
writeReplace()
protected Object writeReplace ()
Replaces this object in the output stream with a serialized form.
Part of Java's serialization magic. Generated sub-classes must override
this method by calling return super.writeReplace();
Returns
Type
Description
Object
a SerializedForm of this message
writeTo(CodedOutputStream output)
public void writeTo ( CodedOutputStream output )
Serializes the message and writes it to output
. This does not flush or close the
stream.
Overrides
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-02-14 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-14 UTC."],[],[]]