com.google.protobuf
Class GeneratedMessage.ExtendableMessage<MessageType extends GeneratedMessage.ExtendableMessage>

java.lang.Object
  extended by com.google.protobuf.AbstractMessage
      extended by com.google.protobuf.GeneratedMessage
          extended by com.google.protobuf.GeneratedMessage.ExtendableMessage<MessageType>
All Implemented Interfaces:
Message
Direct Known Subclasses:
DescriptorProtos.EnumOptions, DescriptorProtos.EnumValueOptions, DescriptorProtos.FieldOptions, DescriptorProtos.FileOptions, DescriptorProtos.MessageOptions, DescriptorProtos.MethodOptions, DescriptorProtos.ServiceOptions
Enclosing class:
GeneratedMessage

public abstract static class GeneratedMessage.ExtendableMessage<MessageType extends GeneratedMessage.ExtendableMessage>
extends GeneratedMessage

Generated message classes for message types that contain extension ranges subclass this.

This class implements type-safe accessors for extensions. They implement all the same operations that you can do with normal fields -- e.g. "has", "get", and "getCount" -- but for extensions. The extensions are identified using instances of the class GeneratedMessage.GeneratedExtension; the protocol compiler generates a static instance of this class for every extension in its input. Through the magic of generics, all is made type-safe.

For example, imagine you have the .proto file:

 option java_class = "MyProto";

 message Foo {
   extensions 1000 to max;
 }

 extend Foo {
   optional int32 bar;
 }
 

Then you might write code like:

 MyProto.Foo foo = getFoo();
 int i = foo.getExtension(MyProto.bar);
 

See also GeneratedMessage.ExtendableBuilder.


Nested Class Summary
protected  class GeneratedMessage.ExtendableMessage.ExtensionWriter
          Used by subclasses to serialize extensions.
 
Nested classes/interfaces inherited from class com.google.protobuf.GeneratedMessage
GeneratedMessage.Builder<BuilderType extends GeneratedMessage.Builder>, GeneratedMessage.ExtendableBuilder<MessageType extends GeneratedMessage.ExtendableMessage,BuilderType extends GeneratedMessage.ExtendableBuilder>, GeneratedMessage.ExtendableMessage<MessageType extends GeneratedMessage.ExtendableMessage>, GeneratedMessage.FieldAccessorTable, GeneratedMessage.GeneratedExtension<ContainingType extends Message,Type>
 
Constructor Summary
protected GeneratedMessage.ExtendableMessage()
           
 
Method Summary
protected  boolean extensionsAreInitialized()
          Called by subclasses to check if all extensions are initialized.
protected  int extensionsSerializedSize()
          Called by subclasses to compute the size of extensions.
 java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> getAllFields()
          Returns a collection of all the fields in this message which are set and their corresponding values.
<Type> Type
getExtension(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension, int index)
          Get one element of a repeated extension.
<Type> Type
getExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)
          Get the value of an extension.
<Type> int
getExtensionCount(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension)
          Get the number of elements in a repeated extension.
 java.lang.Object getField(Descriptors.FieldDescriptor field)
          Obtains the value of the given field, or the default value if it is not set.
 java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
          Gets an element of a repeated field.
 int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
          Gets the number of elements of a repeated field.
 boolean hasExtension(GeneratedMessage.GeneratedExtension<MessageType,?> extension)
          Check if a singular extension is present.
 boolean hasField(Descriptors.FieldDescriptor field)
          Returns true if the given field is set.
 boolean isInitialized()
          Returns true if all required fields in the message and all embedded messages are set, false otherwise.
protected  GeneratedMessage.ExtendableMessage.ExtensionWriter newExtensionWriter()
           
 
Methods inherited from class com.google.protobuf.GeneratedMessage
getDescriptorForType, getUnknownFields, internalGetFieldAccessorTable, newGeneratedExtension, newRepeatedGeneratedExtension
 
Methods inherited from class com.google.protobuf.AbstractMessage
equals, getSerializedSize, hashCode, toByteArray, toByteString, toString, writeDelimitedTo, writeTo, writeTo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.protobuf.Message
getDefaultInstanceForType, newBuilderForType, toBuilder
 

Constructor Detail

GeneratedMessage.ExtendableMessage

protected GeneratedMessage.ExtendableMessage()
Method Detail

hasExtension

public final boolean hasExtension(GeneratedMessage.GeneratedExtension<MessageType,?> extension)
Check if a singular extension is present.


getExtensionCount

public final <Type> int getExtensionCount(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension)
Get the number of elements in a repeated extension.


getExtension

public final <Type> Type getExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)
Get the value of an extension.


getExtension

public final <Type> Type getExtension(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension,
                                      int index)
Get one element of a repeated extension.


extensionsAreInitialized

protected boolean extensionsAreInitialized()
Called by subclasses to check if all extensions are initialized.


isInitialized

public boolean isInitialized()
Description copied from interface: Message
Returns true if all required fields in the message and all embedded messages are set, false otherwise.

Specified by:
isInitialized in interface Message
Overrides:
isInitialized in class GeneratedMessage

newExtensionWriter

protected GeneratedMessage.ExtendableMessage.ExtensionWriter newExtensionWriter()

extensionsSerializedSize

protected int extensionsSerializedSize()
Called by subclasses to compute the size of extensions.


getAllFields

public java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> getAllFields()
Description copied from interface: Message
Returns a collection of all the fields in this message which are set and their corresponding values. A singular ("required" or "optional") field is set iff hasField() returns true for that field. A "repeated" field is set iff getRepeatedFieldSize() is greater than zero. The values are exactly what would be returned by calling Message.getField(Descriptors.FieldDescriptor) for each field. The map is guaranteed to be a sorted map, so iterating over it will return fields in order by field number.

Specified by:
getAllFields in interface Message
Overrides:
getAllFields in class GeneratedMessage

hasField

public boolean hasField(Descriptors.FieldDescriptor field)
Description copied from interface: Message
Returns true if the given field is set. This is exactly equivalent to calling the generated "has" accessor method corresponding to the field.

Specified by:
hasField in interface Message
Overrides:
hasField in class GeneratedMessage

getField

public java.lang.Object getField(Descriptors.FieldDescriptor field)
Description copied from interface: Message
Obtains the value of the given field, or the default value if it is not set. For primitive fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the value is returend. For embedded message fields, the sub-message is returned. For repeated fields, a java.util.List is returned.

Specified by:
getField in interface Message
Overrides:
getField in class GeneratedMessage

getRepeatedFieldCount

public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Description copied from interface: Message
Gets the number of elements of a repeated field. This is exactly equivalent to calling the generated "Count" accessor method corresponding to the field.

Specified by:
getRepeatedFieldCount in interface Message
Overrides:
getRepeatedFieldCount in class GeneratedMessage

getRepeatedField

public java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field,
                                         int index)
Description copied from interface: Message
Gets an element of a repeated field. For primitive fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the value is returend. For embedded message fields, the sub-message is returned.

Specified by:
getRepeatedField in interface Message
Overrides:
getRepeatedField in class GeneratedMessage


Copyright © 2008-2009. All Rights Reserved.