/** Like {@link #writeTo} but uses MessageSet wire format. */ public void writeMessageSetTo(final CodedOutputStream output) throws IOException { for (int i = 0; i < fields.getNumArrayEntries(); i++) { writeMessageSetTo(fields.getArrayEntryAt(i), output); } for (final Map.Entry<FieldDescriptorType, Object> entry : fields.getOverflowEntries()) { writeMessageSetTo(entry, output); } }
/** See {@link Message#writeTo(CodedOutputStream)}. */ public void writeTo(final CodedOutputStream output) throws IOException { for (int i = 0; i < fields.getNumArrayEntries(); i++) { final Map.Entry<FieldDescriptorType, Object> entry = fields.getArrayEntryAt(i); writeField(entry.getKey(), entry.getValue(), output); } for (final Map.Entry<FieldDescriptorType, Object> entry : fields.getOverflowEntries()) { writeField(entry.getKey(), entry.getValue(), output); } }
/** Like {@link #getSerializedSize} but uses MessageSet wire format. */ public int getMessageSetSerializedSize() { int size = 0; for (int i = 0; i < fields.getNumArrayEntries(); i++) { size += getMessageSetSerializedSize(fields.getArrayEntryAt(i)); } for (final Map.Entry<FieldDescriptorType, Object> entry : fields.getOverflowEntries()) { size += getMessageSetSerializedSize(entry); } return size; }
/** * See {@link Message#getSerializedSize()}. It's up to the caller to cache the resulting size if * desired. */ public int getSerializedSize() { int size = 0; for (int i = 0; i < fields.getNumArrayEntries(); i++) { final Map.Entry<FieldDescriptorType, Object> entry = fields.getArrayEntryAt(i); size += computeFieldSize(entry.getKey(), entry.getValue()); } for (final Map.Entry<FieldDescriptorType, Object> entry : fields.getOverflowEntries()) { size += computeFieldSize(entry.getKey(), entry.getValue()); } return size; }
/** * See {@link Message#isInitialized()}. Note: Since {@code 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. */ public boolean isInitialized() { for (int i = 0; i < fields.getNumArrayEntries(); i++) { if (!isInitialized(fields.getArrayEntryAt(i))) { return false; } } for (final Map.Entry<FieldDescriptorType, Object> entry : fields.getOverflowEntries()) { if (!isInitialized(entry)) { return false; } } return true; }
/** * Clones the FieldSet. The returned FieldSet will be mutable even if the original FieldSet was * immutable. * * @return the newly cloned FieldSet */ @Override public FieldSet<FieldDescriptorType> clone() { // We can't just call fields.clone because List objects in the map // should not be shared. FieldSet<FieldDescriptorType> clone = FieldSet.newFieldSet(); for (int i = 0; i < fields.getNumArrayEntries(); i++) { Map.Entry<FieldDescriptorType, Object> entry = fields.getArrayEntryAt(i); FieldDescriptorType descriptor = entry.getKey(); clone.setField(descriptor, entry.getValue()); } for (Map.Entry<FieldDescriptorType, Object> entry : fields.getOverflowEntries()) { FieldDescriptorType descriptor = entry.getKey(); clone.setField(descriptor, entry.getValue()); } return clone; }