示例#1
0
 /** 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);
   }
 }
示例#2
0
 private void writeMessageSetTo(
     final Map.Entry<FieldDescriptorType, Object> entry, final CodedOutputStream output)
     throws IOException {
   final FieldDescriptorType descriptor = entry.getKey();
   if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE
       && !descriptor.isRepeated()
       && !descriptor.isPacked()) {
     output.writeMessageSetExtension(entry.getKey().getNumber(), (MessageLite) entry.getValue());
   } else {
     writeField(descriptor, entry.getValue(), output);
   }
 }
示例#3
0
 public void writeUntil(final int end, final CodedOutputStream output) throws IOException {
   while (next != null && next.getKey().getNumber() < end) {
     ExtensionDescriptor extension = next.getKey();
     if (messageSetWireFormat
         && extension.getLiteJavaType() == WireFormat.JavaType.MESSAGE
         && !extension.isRepeated()) {
       output.writeMessageSetExtension(extension.getNumber(), (MessageLite) next.getValue());
     } else {
       FieldSet.writeField(extension, next.getValue(), output);
     }
     if (iter.hasNext()) {
       next = iter.next();
     } else {
       next = null;
     }
   }
 }
示例#4
0
  public void writeTo(final CodedOutputStream output) throws IOException {
    final boolean isMessageSet = getDescriptorForType().getOptions().getMessageSetWireFormat();

    for (final Map.Entry<FieldDescriptor, Object> entry : getAllFields().entrySet()) {
      final FieldDescriptor field = entry.getKey();
      final Object value = entry.getValue();
      if (isMessageSet
          && field.isExtension()
          && field.getType() == FieldDescriptor.Type.MESSAGE
          && !field.isRepeated()) {
        output.writeMessageSetExtension(field.getNumber(), (Message) value);
      } else {
        FieldSet.writeField(field, value, output);
      }
    }

    final UnknownFieldSet unknownFields = getUnknownFields();
    if (isMessageSet) {
      unknownFields.writeAsMessageSetTo(output);
    } else {
      unknownFields.writeTo(output);
    }
  }