final class FieldSet<FieldDescriptorType extends FieldSet.FieldDescriptorLite<FieldDescriptorType>>
extends java.lang.Object
DynamicMessage
, and also to represent
extensions in GeneratedMessage
. This class is package-private,
since outside users should probably be using DynamicMessage
.Modifier and Type | Class and Description |
---|---|
static interface |
FieldSet.FieldDescriptorLite<T extends FieldSet.FieldDescriptorLite<T>>
Interface for a FieldDescriptor or lite extension descriptor.
|
Modifier and Type | Field and Description |
---|---|
private static FieldSet |
DEFAULT_INSTANCE |
private SmallSortedMap<FieldDescriptorType,java.lang.Object> |
fields |
private boolean |
hasLazyField |
private boolean |
isImmutable |
Modifier | Constructor and Description |
---|---|
private |
FieldSet()
Construct a new FieldSet.
|
private |
FieldSet(boolean dummy)
Construct an empty FieldSet.
|
Modifier and Type | Method and Description |
---|---|
void |
addRepeatedField(FieldDescriptorType descriptor,
java.lang.Object value)
Useful for implementing
Message.Builder.addRepeatedField(Descriptors.FieldDescriptor,Object) . |
void |
clear()
|
void |
clearField(FieldDescriptorType descriptor)
Useful for implementing
Message.Builder.clearField(Descriptors.FieldDescriptor) . |
FieldSet<FieldDescriptorType> |
clone()
Clones the FieldSet.
|
private void |
cloneFieldEntry(java.util.Map<FieldDescriptorType,java.lang.Object> map,
java.util.Map.Entry<FieldDescriptorType,java.lang.Object> entry) |
private java.lang.Object |
cloneIfMutable(java.lang.Object value) |
(package private) static int |
computeElementSize(WireFormat.FieldType type,
int number,
java.lang.Object value)
Compute the number of bytes that would be needed to encode a
single tag/value pair of arbitrary type.
|
(package private) static int |
computeElementSizeNoTag(WireFormat.FieldType type,
java.lang.Object value)
Compute the number of bytes that would be needed to encode a
particular value of arbitrary type, excluding tag.
|
static int |
computeFieldSize(FieldSet.FieldDescriptorLite<?> descriptor,
java.lang.Object value)
Compute the number of bytes needed to encode a particular field.
|
static <T extends FieldSet.FieldDescriptorLite<T>> |
emptySet()
Get an immutable empty FieldSet.
|
boolean |
equals(java.lang.Object o) |
java.util.Map<FieldDescriptorType,java.lang.Object> |
getAllFields()
Get a simple map containing all the fields.
|
java.lang.Object |
getField(FieldDescriptorType descriptor)
Useful for implementing
MessageOrBuilder.getField(Descriptors.FieldDescriptor) . |
int |
getMessageSetSerializedSize()
Like
getSerializedSize() but uses MessageSet wire format. |
private int |
getMessageSetSerializedSize(java.util.Map.Entry<FieldDescriptorType,java.lang.Object> entry) |
java.lang.Object |
getRepeatedField(FieldDescriptorType descriptor,
int index)
Useful for implementing
MessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int) . |
int |
getRepeatedFieldCount(FieldDescriptorType descriptor)
Useful for implementing
MessageOrBuilder.getRepeatedFieldCount(Descriptors.FieldDescriptor) . |
int |
getSerializedSize()
|
(package private) static int |
getWireFormatForFieldType(WireFormat.FieldType type,
boolean isPacked)
Given a field type, return the wire type.
|
boolean |
hasField(FieldDescriptorType descriptor)
Useful for implementing
MessageOrBuilder.hasField(Descriptors.FieldDescriptor) . |
int |
hashCode() |
boolean |
isImmutable()
Returns whether the FieldSet is immutable.
|
boolean |
isInitialized()
|
private boolean |
isInitialized(java.util.Map.Entry<FieldDescriptorType,java.lang.Object> entry) |
java.util.Iterator<java.util.Map.Entry<FieldDescriptorType,java.lang.Object>> |
iterator()
Get an iterator to the field map.
|
void |
makeImmutable()
Make this FieldSet immutable from this point forward.
|
void |
mergeFrom(FieldSet<FieldDescriptorType> other)
Like
Message.Builder.mergeFrom(Message) , but merges from another
FieldSet . |
private void |
mergeFromField(java.util.Map.Entry<FieldDescriptorType,java.lang.Object> entry) |
static <T extends FieldSet.FieldDescriptorLite<T>> |
newFieldSet()
Construct a new FieldSet.
|
static java.lang.Object |
readPrimitiveField(CodedInputStream input,
WireFormat.FieldType type,
boolean checkUtf8)
Read a field of any primitive type for immutable messages from a
CodedInputStream.
|
void |
setField(FieldDescriptorType descriptor,
java.lang.Object value)
Useful for implementing
Message.Builder.setField(Descriptors.FieldDescriptor,Object) . |
void |
setRepeatedField(FieldDescriptorType descriptor,
int index,
java.lang.Object value)
Useful for implementing
Message.Builder.setRepeatedField(Descriptors.FieldDescriptor,int,Object) . |
private static void |
verifyType(WireFormat.FieldType type,
java.lang.Object value)
Verifies that the given object is of the correct type to be a valid
value for the given field.
|
(package private) static void |
writeElement(CodedOutputStream output,
WireFormat.FieldType type,
int number,
java.lang.Object value)
Write a single tag-value pair to the stream.
|
(package private) static void |
writeElementNoTag(CodedOutputStream output,
WireFormat.FieldType type,
java.lang.Object value)
Write a field of arbitrary type, without its tag, to the stream.
|
static void |
writeField(FieldSet.FieldDescriptorLite<?> descriptor,
java.lang.Object value,
CodedOutputStream output)
Write a single field.
|
void |
writeMessageSetTo(CodedOutputStream output)
Like
writeTo(com.google.protobuf.CodedOutputStream) but uses MessageSet wire format. |
private void |
writeMessageSetTo(java.util.Map.Entry<FieldDescriptorType,java.lang.Object> entry,
CodedOutputStream output) |
void |
writeTo(CodedOutputStream output)
|
private final SmallSortedMap<FieldDescriptorType extends FieldSet.FieldDescriptorLite<FieldDescriptorType>,java.lang.Object> fields
private boolean isImmutable
private boolean hasLazyField
private static final FieldSet DEFAULT_INSTANCE
private FieldSet()
private FieldSet(boolean dummy)
public static <T extends FieldSet.FieldDescriptorLite<T>> FieldSet<T> newFieldSet()
public static <T extends FieldSet.FieldDescriptorLite<T>> FieldSet<T> emptySet()
public void makeImmutable()
public boolean isImmutable()
emptySet()
or if makeImmutable()
were called.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public FieldSet<FieldDescriptorType> clone()
clone
in class java.lang.Object
public void clear()
public java.util.Map<FieldDescriptorType,java.lang.Object> getAllFields()
private void cloneFieldEntry(java.util.Map<FieldDescriptorType,java.lang.Object> map, java.util.Map.Entry<FieldDescriptorType,java.lang.Object> entry)
public java.util.Iterator<java.util.Map.Entry<FieldDescriptorType,java.lang.Object>> iterator()
public boolean hasField(FieldDescriptorType descriptor)
MessageOrBuilder.hasField(Descriptors.FieldDescriptor)
.public java.lang.Object getField(FieldDescriptorType descriptor)
MessageOrBuilder.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.public void setField(FieldDescriptorType descriptor, java.lang.Object value)
Message.Builder.setField(Descriptors.FieldDescriptor,Object)
.public void clearField(FieldDescriptorType descriptor)
Message.Builder.clearField(Descriptors.FieldDescriptor)
.public int getRepeatedFieldCount(FieldDescriptorType descriptor)
MessageOrBuilder.getRepeatedFieldCount(Descriptors.FieldDescriptor)
.public java.lang.Object getRepeatedField(FieldDescriptorType descriptor, int index)
MessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int)
.public void setRepeatedField(FieldDescriptorType descriptor, int index, java.lang.Object value)
Message.Builder.setRepeatedField(Descriptors.FieldDescriptor,int,Object)
.public void addRepeatedField(FieldDescriptorType descriptor, java.lang.Object value)
Message.Builder.addRepeatedField(Descriptors.FieldDescriptor,Object)
.private static void verifyType(WireFormat.FieldType type, java.lang.Object value)
java.lang.IllegalArgumentException
- The value is not of the right type.public boolean isInitialized()
MessageLiteOrBuilder.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.private boolean isInitialized(java.util.Map.Entry<FieldDescriptorType,java.lang.Object> entry)
static int getWireFormatForFieldType(WireFormat.FieldType type, boolean isPacked)
public void mergeFrom(FieldSet<FieldDescriptorType> other)
Message.Builder.mergeFrom(Message)
, but merges from another
FieldSet
.private java.lang.Object cloneIfMutable(java.lang.Object value)
private void mergeFromField(java.util.Map.Entry<FieldDescriptorType,java.lang.Object> entry)
public static java.lang.Object readPrimitiveField(CodedInputStream input, WireFormat.FieldType type, boolean checkUtf8) throws java.io.IOException
input
- The stream from which to read.type
- Declared type of the field.checkUtf8
- When true, check that the input is valid utf8.MessageOrBuilder.getField(Descriptors.FieldDescriptor)
for
this field.java.io.IOException
public void writeTo(CodedOutputStream output) throws java.io.IOException
java.io.IOException
public void writeMessageSetTo(CodedOutputStream output) throws java.io.IOException
writeTo(com.google.protobuf.CodedOutputStream)
but uses MessageSet wire format.java.io.IOException
private void writeMessageSetTo(java.util.Map.Entry<FieldDescriptorType,java.lang.Object> entry, CodedOutputStream output) throws java.io.IOException
java.io.IOException
static void writeElement(CodedOutputStream output, WireFormat.FieldType type, int number, java.lang.Object value) throws java.io.IOException
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 by
MessageOrBuilder.getField(Descriptors.FieldDescriptor)
for
this field.java.io.IOException
static void writeElementNoTag(CodedOutputStream output, WireFormat.FieldType type, java.lang.Object value) throws java.io.IOException
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 by
MessageOrBuilder.getField(Descriptors.FieldDescriptor)
for
this field.java.io.IOException
public static void writeField(FieldSet.FieldDescriptorLite<?> descriptor, java.lang.Object value, CodedOutputStream output) throws java.io.IOException
java.io.IOException
public int getSerializedSize()
MessageLite.getSerializedSize()
. It's up to the caller to cache
the resulting size if desired.public int getMessageSetSerializedSize()
getSerializedSize()
but uses MessageSet wire format.private int getMessageSetSerializedSize(java.util.Map.Entry<FieldDescriptorType,java.lang.Object> entry)
static int computeElementSize(WireFormat.FieldType type, int number, java.lang.Object value)
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 by
MessageOrBuilder.getField(Descriptors.FieldDescriptor)
for
this field.static int computeElementSizeNoTag(WireFormat.FieldType type, java.lang.Object value)
type
- The field's type.value
- Object representing the field's value. Must be of the exact
type which would be returned by
MessageOrBuilder.getField(Descriptors.FieldDescriptor)
for
this field.public static int computeFieldSize(FieldSet.FieldDescriptorLite<?> descriptor, java.lang.Object value)