Top Description Inners Fields Constructors Methods
com.google.protobuf

pack-priv final Class FieldSet<FieldDescriptorType extends FieldSet.FieldDescriptorLite<FieldDescriptorType>>

extends Object
Class Inheritance
Static Imports
com.google.protobuf.Internal.checkNotNull

A class which represents an arbitrary set of fields of some message type. This is used to implement DynamicMessage, and also to represent extensions in GeneratedMessage. This class is package-private, since outside users should probably be using DynamicMessage.
Author
[email protected] Kenton Varda

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
FieldSet.FieldDescriptorLite<T extends FieldSet.FieldDescriptorLite<T>>

Interface for a FieldDescriptor or lite extension descriptor.

Field Summary

Modifier and TypeField and Description
private static final FieldSet<FieldDescriptorType extends FieldSet.FieldDescriptorLite<FieldDescriptorType>>
private final SmallSortedMap<FieldDescriptorType, Object>
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
private
FieldSet()

Construct a new FieldSet.

private
FieldSet(final boolean dummy)

Construct an empty FieldSet.

Method Summary

Modifier and TypeMethod and Description
public void
addRepeatedField(final FieldDescriptorType descriptor, final Object value)

Useful for implementing Message.Builder#addRepeatedField(Descriptors.FieldDescriptor, Object).

public void
public void
clearField(final FieldDescriptorType descriptor)

Useful for implementing Message.Builder#clearField(Descriptors.FieldDescriptor).

public FieldSet<FieldDescriptorType>

Returns:

the newly cloned FieldSet
clone
()

Overrides java.lang.Object.clone.

Clones the FieldSet.
private void
cloneFieldEntry(Map<FieldDescriptorType, Object> map, Map.Entry<FieldDescriptorType, Object> entry)

private Object
pack-priv static int
computeElementSize(final WireFormat.FieldType
The field's type.
type
,
final int
The field's number.
number
,
final Object
Object representing the field's value. Must be of the exact type which would be returned by Message#getField(Descriptors.FieldDescriptor) for this field.
value
)

Compute the number of bytes that would be needed to encode a single tag/value pair of arbitrary type.

pack-priv static int
computeElementSizeNoTag(final WireFormat.FieldType
The field's type.
type
,
final Object
Object representing the field's value. Must be of the exact type which would be returned by Message#getField(Descriptors.FieldDescriptor) for this field.
value
)

Compute the number of bytes that would be needed to encode a particular value of arbitrary type, excluding tag.

public static int
computeFieldSize(final FieldSet.FieldDescriptorLite<?> descriptor, final Object value)

Compute the number of bytes needed to encode a particular field.

public static <T extends FieldSet.FieldDescriptorLite<T>> FieldSet<T>
emptySet()

Get an immutable empty FieldSet.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Map<FieldDescriptorType, Object>
getAllFields()

Get a simple map containing all the fields.

public Object
getField(final FieldDescriptorType descriptor)

Useful for implementing Message#getField(Descriptors.FieldDescriptor).

public int
getMessageSetSerializedSize()

Like getSerializedSize but uses MessageSet wire format.

private int
getMessageSetSerializedSize(final Map.Entry<FieldDescriptorType, Object> entry)

public Object
getRepeatedField(final FieldDescriptorType descriptor, final int index)

Useful for implementing Message#getRepeatedField(Descriptors.FieldDescriptor, int).

public int
getRepeatedFieldCount(final FieldDescriptorType descriptor)

Useful for implementing Message#getRepeatedFieldCount(Descriptors.FieldDescriptor).

public int
pack-priv static int

Returns:

One of the WIRETYPE_ constants defined in WireFormat.
getWireFormatForFieldType
(final WireFormat.FieldType type, boolean isPacked)

Given a field type, return the wire type.

public boolean
hasField(final FieldDescriptorType descriptor)

Useful for implementing Message#hasField(Descriptors.FieldDescriptor).

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
pack-priv boolean
isEmpty()

Returns true if empty, false otherwise.

public boolean

Returns:

whether the FieldSet is immutable.
isImmutable
()

Returns whether the FieldSet is immutable.

public boolean
private boolean
isInitialized(final Map.Entry<FieldDescriptorType, Object> entry)

public Iterator<Map.Entry<FieldDescriptorType, Object>>
iterator()

Get an iterator to the field map.

public void
makeImmutable()

Make this FieldSet immutable from this point forward.

public void
mergeFrom(final FieldSet<FieldDescriptorType> other)

Like Message.Builder#mergeFrom(Message), but merges from another FieldSet.

private void
mergeFromField(final Map.Entry<FieldDescriptorType, Object> entry)

public static <T extends FieldSet.FieldDescriptorLite<T>> FieldSet<T>
newFieldSet()

Construct a new FieldSet.

public static Object

Returns:

An object representing the field's value, of the exact type which would be returned by Message#getField(Descriptors.FieldDescriptor) for this field.
readPrimitiveField
(CodedInputStream
The stream from which to read.
input
,
final WireFormat.FieldType
Declared type of the field.
type
,
boolean
When true, check that the input is valid utf8.
checkUtf8
)

Read a field of any primitive type for immutable messages from a CodedInputStream.

public void
setField(final FieldDescriptorType descriptor, Object value)

Useful for implementing Message.Builder#setField(Descriptors.FieldDescriptor, Object).

public void
setRepeatedField(final FieldDescriptorType descriptor, final int index, final Object value)

Useful for implementing Message.Builder#setRepeatedField(Descriptors.FieldDescriptor, int, Object).

private static void
verifyType(final WireFormat.FieldType type, final Object value)

Verifies that the given object is of the correct type to be a valid value for the given field.

pack-priv static void
writeElement(final CodedOutputStream
The output stream.
output
,
final WireFormat.FieldType
The field's type.
type
,
final int
The field's number.
number
,
final Object
Object representing the field's value. Must be of the exact type which would be returned by Message#getField(Descriptors.FieldDescriptor) for this field.
value
)

Write a single tag-value pair to the stream.

pack-priv static void
writeElementNoTag(final CodedOutputStream
The output stream.
output
,
final WireFormat.FieldType
The field's type.
type
,
final Object
Object representing the field's value. Must be of the exact type which would be returned by Message#getField(Descriptors.FieldDescriptor) for this field.
value
)

Write a field of arbitrary type, without its tag, to the stream.

public static void
writeField(final FieldSet.FieldDescriptorLite<?> descriptor, final Object value, final CodedOutputStream output)

Write a single field.

public void
writeMessageSetTo(final CodedOutputStream output)

Like writeTo but uses MessageSet wire format.

private void
writeMessageSetTo(final Map.Entry<FieldDescriptorType, Object> entry, final CodedOutputStream output)

public void
Inherited from java.lang.Object:
finalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_INSTANCEback to summary
private static final FieldSet<FieldDescriptorType extends FieldSet.FieldDescriptorLite<FieldDescriptorType>> DEFAULT_INSTANCE
Annotations
@SuppressWarnings:rawtypes
fieldsback to summary
private final SmallSortedMap<FieldDescriptorType, Object> fields
hasLazyFieldback to summary
private boolean hasLazyField
isImmutableback to summary
private boolean isImmutable

Constructor Detail

FieldSetback to summary
private FieldSet()

Construct a new FieldSet.

FieldSetback to summary
private FieldSet(final boolean dummy)

Construct an empty FieldSet. This is only used to initialize DEFAULT_INSTANCE.

Method Detail

addRepeatedFieldback to summary
public void addRepeatedField(final FieldDescriptorType descriptor, final Object value)

Useful for implementing Message.Builder#addRepeatedField(Descriptors.FieldDescriptor, Object).

Annotations
@SuppressWarnings:unchecked
clearback to summary
public void clear()

See Message.Builder#clear().

clearFieldback to summary
public void clearField(final FieldDescriptorType descriptor)

Useful for implementing Message.Builder#clearField(Descriptors.FieldDescriptor).

cloneback to summary
public FieldSet<FieldDescriptorType> clone()

Overrides java.lang.Object.clone.

Clones the FieldSet. The returned FieldSet will be mutable even if the original FieldSet was immutable.

Returns:FieldSet<FieldDescriptorType>

the newly cloned FieldSet

Annotations
@Override
cloneFieldEntryback to summary
private void cloneFieldEntry(Map<FieldDescriptorType, Object> map, Map.Entry<FieldDescriptorType, Object> entry)
cloneIfMutableback to summary
private Object cloneIfMutable(Object value)
computeElementSizeback to summary
pack-priv static int computeElementSize(final WireFormat.FieldType type, final int number, final Object value)

Compute the number of bytes that would be needed to encode a single tag/value pair of arbitrary type.

Parameters
type:WireFormat.FieldType

The field's type.

number:int

The field's number.

value:Object

Object representing the field's value. Must be of the exact type which would be returned by Message#getField(Descriptors.FieldDescriptor) for this field.

computeElementSizeNoTagback to summary
pack-priv static int computeElementSizeNoTag(final WireFormat.FieldType type, final Object value)

Compute the number of bytes that would be needed to encode a particular value of arbitrary type, excluding tag.

Parameters
type:WireFormat.FieldType

The field's type.

value:Object

Object representing the field's value. Must be of the exact type which would be returned by Message#getField(Descriptors.FieldDescriptor) for this field.

computeFieldSizeback to summary
public static int computeFieldSize(final FieldSet.FieldDescriptorLite<?> descriptor, final Object value)

Compute the number of bytes needed to encode a particular field.

emptySetback to summary
public static <T extends FieldSet.FieldDescriptorLite<T>> FieldSet<T> emptySet()

Get an immutable empty FieldSet.

Annotations
@SuppressWarnings:unchecked
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getAllFieldsback to summary
public Map<FieldDescriptorType, Object> getAllFields()

Get a simple map containing all the fields.

getFieldback to summary
public Object getField(final FieldDescriptorType descriptor)

Useful for implementing Message#getField(Descriptors.FieldDescriptor). This method returns null if the field is not set; in this case it is up to the caller to fetch the field's default value.

getMessageSetSerializedSizeback to summary
public int getMessageSetSerializedSize()

Like getSerializedSize but uses MessageSet wire format.

getMessageSetSerializedSizeback to summary
private int getMessageSetSerializedSize(final Map.Entry<FieldDescriptorType, Object> entry)
getRepeatedFieldback to summary
public Object getRepeatedField(final FieldDescriptorType descriptor, final int index)

Useful for implementing Message#getRepeatedField(Descriptors.FieldDescriptor, int).

getRepeatedFieldCountback to summary
public int getRepeatedFieldCount(final FieldDescriptorType descriptor)

Useful for implementing Message#getRepeatedFieldCount(Descriptors.FieldDescriptor).

getSerializedSizeback to summary
public int getSerializedSize()

See Message#getSerializedSize(). It's up to the caller to cache the resulting size if desired.

getWireFormatForFieldTypeback to summary
pack-priv static int getWireFormatForFieldType(final WireFormat.FieldType type, boolean isPacked)

Given a field type, return the wire type.

Returns:int

One of the WIRETYPE_ constants defined in WireFormat.

hasFieldback to summary
public boolean hasField(final FieldDescriptorType descriptor)

Useful for implementing Message#hasField(Descriptors.FieldDescriptor).

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isEmptyback to summary
pack-priv boolean isEmpty()

Returns true if empty, false otherwise.

isImmutableback to summary
public boolean isImmutable()

Returns whether the FieldSet is immutable. This is true if it is the emptySet or if makeImmutable were called.

Returns:boolean

whether the FieldSet is immutable.

isInitializedback to summary
public boolean isInitialized()

See Message#isInitialized().

Note

Since FieldSet itself does not have any way of knowing about required fields that aren't actually present in the set, it is up to the caller to check that all required fields are present.

isInitializedback to summary
private boolean isInitialized(final Map.Entry<FieldDescriptorType, Object> entry)
Annotations
@SuppressWarnings:unchecked
iteratorback to summary
public Iterator<Map.Entry<FieldDescriptorType, Object>> iterator()

Get an iterator to the field map. This iterator should not be leaked out of the protobuf library as it is not protected from mutation when fields is not immutable.

makeImmutableback to summary
public void makeImmutable()

Make this FieldSet immutable from this point forward.

Annotations
@SuppressWarnings:unchecked
mergeFromback to summary
public void mergeFrom(final FieldSet<FieldDescriptorType> other)

Like Message.Builder#mergeFrom(Message), but merges from another FieldSet.

mergeFromFieldback to summary
private void mergeFromField(final Map.Entry<FieldDescriptorType, Object> entry)
Annotations
@SuppressWarnings:unchecked, rawtypes
newFieldSetback to summary
public static <T extends FieldSet.FieldDescriptorLite<T>> FieldSet<T> newFieldSet()

Construct a new FieldSet.

readPrimitiveFieldback to summary
public static Object readPrimitiveField(CodedInputStream input, final WireFormat.FieldType type, boolean checkUtf8) throws IOException

Read a field of any primitive type for immutable messages from a CodedInputStream. Enums, groups, and embedded messages are not handled by this method.

Parameters
input:CodedInputStream

The stream from which to read.

type:WireFormat.FieldType

Declared type of the field.

checkUtf8:boolean

When true, check that the input is valid utf8.

Returns:Object

An object representing the field's value, of the exact type which would be returned by Message#getField(Descriptors.FieldDescriptor) for this field.

setFieldback to summary
public void setField(final FieldDescriptorType descriptor, Object value)

Useful for implementing Message.Builder#setField(Descriptors.FieldDescriptor, Object).

Annotations
@SuppressWarnings:unchecked, rawtypes
setRepeatedFieldback to summary
public void setRepeatedField(final FieldDescriptorType descriptor, final int index, final Object value)

Useful for implementing Message.Builder#setRepeatedField(Descriptors.FieldDescriptor, int, Object).

Annotations
@SuppressWarnings:unchecked
verifyTypeback to summary
private static void verifyType(final WireFormat.FieldType type, final Object value)

Verifies that the given object is of the correct type to be a valid value for the given field. (For repeated fields, this checks if the object is the right type to be one element of the field.)

Exceptions
IllegalArgumentException:
The value is not of the right type.
writeElementback to summary
pack-priv static void writeElement(final CodedOutputStream output, final WireFormat.FieldType type, final int number, final Object value) throws IOException

Write a single tag-value pair to the stream.

Parameters
output:CodedOutputStream

The output stream.

type:WireFormat.FieldType

The field's type.

number:int

The field's number.

value:Object

Object representing the field's value. Must be of the exact type which would be returned by Message#getField(Descriptors.FieldDescriptor) for this field.

writeElementNoTagback to summary
pack-priv static void writeElementNoTag(final CodedOutputStream output, final WireFormat.FieldType type, final Object value) throws IOException

Write a field of arbitrary type, without its tag, to the stream.

Parameters
output:CodedOutputStream

The output stream.

type:WireFormat.FieldType

The field's type.

value:Object

Object representing the field's value. Must be of the exact type which would be returned by Message#getField(Descriptors.FieldDescriptor) for this field.

writeFieldback to summary
public static void writeField(final FieldSet.FieldDescriptorLite<?> descriptor, final Object value, final CodedOutputStream output) throws IOException

Write a single field.

writeMessageSetToback to summary
public void writeMessageSetTo(final CodedOutputStream output) throws IOException

Like writeTo but uses MessageSet wire format.

writeMessageSetToback to summary
private void writeMessageSetTo(final Map.Entry<FieldDescriptorType, Object> entry, final CodedOutputStream output) throws IOException
writeToback to summary
public void writeTo(final CodedOutputStream output) throws IOException

See Message#writeTo(CodedOutputStream).

com.google.protobuf back to summary

public Interface FieldSet.FieldDescriptorLite<T extends FieldSet.FieldDescriptorLite<T>>

extends Comparable<T extends FieldSet.FieldDescriptorLite<T>>
Known Direct Implementers
com.google.protobuf.GeneratedMessageLite.ExtensionDescriptor, com.google.protobuf.Descriptors.FieldDescriptor

Interface for a FieldDescriptor or lite extension descriptor. This prevents FieldSet from depending on Descriptors.FieldDescriptor.

Method Summary

Modifier and TypeMethod and Description
public Internal.EnumLiteMap<?>
public WireFormat.JavaType
public WireFormat.FieldType
public int
public MessageLite.Builder
public boolean
public boolean
Inherited from java.lang.Comparable:
compareTo

Method Detail

getEnumTypeback to summary
public Internal.EnumLiteMap<?> getEnumType()
getLiteJavaTypeback to summary
public WireFormat.JavaType getLiteJavaType()
getLiteTypeback to summary
public WireFormat.FieldType getLiteType()
getNumberback to summary
public int getNumber()
internalMergeFromback to summary
public MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from)
isPackedback to summary
public boolean isPacked()
isRepeatedback to summary
public boolean isRepeated()