Class FieldSet<T extends FieldSet.FieldDescriptorLite<T>>
java.lang.Object
com.google.protobuf.FieldSet<T>
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classFieldSet.Builder<T extends FieldSet.FieldDescriptorLite<T>>A FieldSet Builder that accept aMessageLite.Builderas a field value.static interfaceInterface for a FieldDescriptor or lite extension descriptor. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final FieldSet<?> private final SmallSortedMap<T, Object> private booleanprivate boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRepeatedField(T descriptor, Object value) Useful for implementingMessage.Builder.addRepeatedField(Descriptors.FieldDescriptor,Object).voidclear()voidclearField(T descriptor) Useful for implementingMessage.Builder.clearField(Descriptors.FieldDescriptor).clone()Clones the FieldSet.private static <T extends FieldSet.FieldDescriptorLite<T>>
SmallSortedMap<T, Object> cloneAllFieldsMap(SmallSortedMap<T, Object> fields, boolean copyList, boolean resolveLazyFields) private static <T extends FieldSet.FieldDescriptorLite<T>>
voidcloneFieldEntry(Map<T, Object> map, Map.Entry<T, Object> entry, boolean copyList, boolean resolveLazyFields) private static ObjectcloneIfMutable(Object value) (package private) static intcomputeElementSize(WireFormat.FieldType type, int number, Object value) Compute the number of bytes that would be needed to encode a single tag/value pair of arbitrary type.(package private) static intcomputeElementSizeNoTag(WireFormat.FieldType type, Object value) Compute the number of bytes that would be needed to encode a particular value of arbitrary type, excluding tag.static intcomputeFieldSize(FieldSet.FieldDescriptorLite<?> descriptor, Object value) Compute the number of bytes needed to encode a particular field.Get an iterator over the fields in the map in descending (i.e.static <T extends FieldSet.FieldDescriptorLite<T>>
FieldSet<T> emptySet()Get an immutable empty FieldSet.booleanGet a simple map containing all the fields.Useful for implementingMessageOrBuilder.getField(Descriptors.FieldDescriptor).intLikegetSerializedSize()but uses MessageSet wire format.private intgetMessageSetSerializedSize(Map.Entry<T, Object> entry) getRepeatedField(T descriptor, int index) Useful for implementingMessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int).intgetRepeatedFieldCount(T descriptor) Useful for implementingMessageOrBuilder.getRepeatedFieldCount(Descriptors.FieldDescriptor).int(package private) static intgetWireFormatForFieldType(WireFormat.FieldType type, boolean isPacked) Given a field type, return the wire type.booleanUseful for implementingMessageOrBuilder.hasField(Descriptors.FieldDescriptor).inthashCode()(package private) booleanisEmpty()Returnstrueif empty,falseotherwise.booleanReturns whether the FieldSet is immutable.booleanprivate static <T extends FieldSet.FieldDescriptorLite<T>>
booleanisInitialized(Map.Entry<T, Object> entry) private static booleanprivate static booleanisValidType(WireFormat.FieldType type, Object value) iterator()Get an iterator to the field map.(package private) booleanlazyFieldCorrupted(T descriptor) Returns true if the field is a lazy field and it is corrupted.voidMake this FieldSet immutable from this point forward.voidLikeMessage.Builder.mergeFrom(Message), but merges from anotherFieldSet.private voidmergeFromField(Map.Entry<T, Object> entry) static <T extends FieldSet.FieldDescriptorLite<T>>
FieldSet.Builder<T> Construct a new Builder.static <T extends FieldSet.FieldDescriptorLite<T>>
FieldSet<T> Construct a new FieldSet.static ObjectreadPrimitiveField(CodedInputStream input, WireFormat.FieldType type, boolean checkUtf8) Read a field of any primitive type for immutable messages from a CodedInputStream.voidUseful for implementingMessage.Builder.setField(Descriptors.FieldDescriptor,Object).voidsetRepeatedField(T descriptor, int index, Object value) Useful for implementingMessage.Builder.setRepeatedField(Descriptors.FieldDescriptor,int,Object).private voidverifyType(T descriptor, Object value) Verifies that the given object is of the correct type to be a valid value for the given field.(package private) static voidwriteElement(CodedOutputStream output, WireFormat.FieldType type, int number, Object value) Write a single tag-value pair to the stream.(package private) static voidwriteElementNoTag(CodedOutputStream output, WireFormat.FieldType type, Object value) Write a field of arbitrary type, without its tag, to the stream.static voidwriteField(FieldSet.FieldDescriptorLite<?> descriptor, Object value, CodedOutputStream output) Write a single field.voidwriteMessageSetTo(CodedOutputStream output) LikewriteTo(CodedOutputStream)but uses MessageSet wire format.private voidwriteMessageSetTo(Map.Entry<T, Object> entry, CodedOutputStream output) voidwriteTo(CodedOutputStream output)
-
Field Details
-
fields
-
isImmutable
private boolean isImmutable -
hasLazyField
private boolean hasLazyField -
DEFAULT_INSTANCE
-
-
Constructor Details
-
FieldSet
private FieldSet()Construct a new FieldSet. -
FieldSet
private FieldSet(boolean dummy) Construct an empty FieldSet. This is only used to initialize DEFAULT_INSTANCE. -
FieldSet
-
-
Method Details
-
newFieldSet
Construct a new FieldSet. -
emptySet
Get an immutable empty FieldSet. -
newBuilder
Construct a new Builder. -
isEmpty
boolean isEmpty()Returnstrueif empty,falseotherwise. -
makeImmutable
public void makeImmutable()Make this FieldSet immutable from this point forward. -
isImmutable
public boolean isImmutable()Returns whether the FieldSet is immutable. This is true if it is theemptySet()or ifmakeImmutable()were called.- Returns:
- whether the FieldSet is immutable.
-
equals
-
hashCode
-
clone
-
clear
public void clear() -
getAllFields
-
cloneAllFieldsMap
private static <T extends FieldSet.FieldDescriptorLite<T>> SmallSortedMap<T,Object> cloneAllFieldsMap(SmallSortedMap<T, Object> fields, boolean copyList, boolean resolveLazyFields) -
cloneFieldEntry
private static <T extends FieldSet.FieldDescriptorLite<T>> void cloneFieldEntry(Map<T, Object> map, Map.Entry<T, Object> entry, boolean copyList, boolean resolveLazyFields) -
iterator
-
descendingIterator
-
hasField
Useful for implementingMessageOrBuilder.hasField(Descriptors.FieldDescriptor). -
getField
Useful for implementingMessageOrBuilder.getField(Descriptors.FieldDescriptor). This method returnsnullif the field is not set; in this case it is up to the caller to fetch the field's default value. -
lazyFieldCorrupted
Returns true if the field is a lazy field and it is corrupted. -
setField
Useful for implementingMessage.Builder.setField(Descriptors.FieldDescriptor,Object). -
clearField
Useful for implementingMessage.Builder.clearField(Descriptors.FieldDescriptor). -
getRepeatedFieldCount
Useful for implementingMessageOrBuilder.getRepeatedFieldCount(Descriptors.FieldDescriptor). -
getRepeatedField
Useful for implementingMessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int). -
setRepeatedField
Useful for implementingMessage.Builder.setRepeatedField(Descriptors.FieldDescriptor,int,Object). -
addRepeatedField
Useful for implementingMessage.Builder.addRepeatedField(Descriptors.FieldDescriptor,Object). -
verifyType
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.)- Throws:
IllegalArgumentException- the value is not of the right type
-
isValidType
-
isInitialized
public boolean isInitialized()SeeMessageLiteOrBuilder.isInitialized(). Note: SinceFieldSetitself 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. -
isInitialized
private static <T extends FieldSet.FieldDescriptorLite<T>> boolean isInitialized(Map.Entry<T, Object> entry) -
isMessageFieldValueInitialized
-
getWireFormatForFieldType
Given a field type, return the wire type.- Returns:
- One of the
WIRETYPE_constants defined inWireFormat.
-
mergeFrom
LikeMessage.Builder.mergeFrom(Message), but merges from anotherFieldSet. -
cloneIfMutable
-
mergeFromField
-
readPrimitiveField
public static Object readPrimitiveField(CodedInputStream input, 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- the stream from which to readtype- declared type of the fieldcheckUtf8- When true, check that the input is valid UTF-8- Returns:
- an object representing the field's value, of the exact type which would be returned by
MessageOrBuilder.getField(Descriptors.FieldDescriptor)for this field - Throws:
IOException
-
writeTo
- Throws:
IOException
-
writeMessageSetTo
LikewriteTo(CodedOutputStream)but uses MessageSet wire format.- Throws:
IOException
-
writeMessageSetTo
private void writeMessageSetTo(Map.Entry<T, Object> entry, CodedOutputStream output) throws IOException- Throws:
IOException
-
writeElement
static void writeElement(CodedOutputStream output, WireFormat.FieldType type, int number, Object value) throws IOException Write a single tag-value pair to the stream.- Parameters:
output- The output stream.type- The field's type.number- The field's number.value- Object representing the field's value. Must be of the exact type which would be returned byMessageOrBuilder.getField(Descriptors.FieldDescriptor)for this field.- Throws:
IOException
-
writeElementNoTag
static void writeElementNoTag(CodedOutputStream output, WireFormat.FieldType type, Object value) throws IOException Write a field of arbitrary type, without its tag, to the stream.- Parameters:
output- The output stream.type- The field's type.value- Object representing the field's value. Must be of the exact type which would be returned byMessageOrBuilder.getField(Descriptors.FieldDescriptor)for this field.- Throws:
IOException
-
writeField
public static void writeField(FieldSet.FieldDescriptorLite<?> descriptor, Object value, CodedOutputStream output) throws IOException Write a single field.- Throws:
IOException
-
getSerializedSize
public int getSerializedSize()SeeMessageLite.getSerializedSize(). It's up to the caller to cache the resulting size if desired. -
getMessageSetSerializedSize
public int getMessageSetSerializedSize()LikegetSerializedSize()but uses MessageSet wire format. -
getMessageSetSerializedSize
-
computeElementSize
Compute the number of bytes that would be needed to encode a single tag/value pair of arbitrary type.- Parameters:
type- The field's type.number- The field's number.value- Object representing the field's value. Must be of the exact type which would be returned byMessageOrBuilder.getField(Descriptors.FieldDescriptor)for this field.
-
computeElementSizeNoTag
Compute the number of bytes that would be needed to encode a particular value of arbitrary type, excluding tag.- Parameters:
type- The field's type.value- Object representing the field's value. Must be of the exact type which would be returned byMessageOrBuilder.getField(Descriptors.FieldDescriptor)for this field.
-
computeFieldSize
Compute the number of bytes needed to encode a particular field.
-