com.google.protobuf.GeneratedMessage.ExtendableBuilder Java Examples

The following examples show how to use com.google.protobuf.GeneratedMessage.ExtendableBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractMessage.java    From travelguide with Apache License 2.0 4 votes vote down vote up
private static void mergeMessageSetExtensionFromBytes(
    ByteString rawBytes,
    ExtensionRegistry.ExtensionInfo extension,
    ExtensionRegistryLite extensionRegistry,
    Message.Builder builder,
    FieldSet<FieldDescriptor> extensions) throws IOException {

  FieldDescriptor field = extension.descriptor;
  boolean hasOriginalValue = hasOriginalMessage(builder, extensions, field);

  if (hasOriginalValue || ExtensionRegistryLite.isEagerlyParseMessageSets()) {
    // If the field already exists, we just parse the field.
    Message value = null;
    if (hasOriginalValue) {
      Message originalMessage =
          getOriginalMessage(builder, extensions, field);
      Message.Builder subBuilder= originalMessage.toBuilder();
      subBuilder.mergeFrom(rawBytes, extensionRegistry);
      value = subBuilder.buildPartial();
    } else {
      value = extension.defaultInstance.getParserForType()
          .parsePartialFrom(rawBytes, extensionRegistry);
    }
    setField(builder, extensions, field, value);
  } else {
    // Use LazyField to load MessageSet lazily.
    LazyField lazyField = new LazyField(
        extension.defaultInstance, extensionRegistry, rawBytes);
    if (builder != null) {
      // TODO(xiangl): it looks like this method can only be invoked by
      // ExtendableBuilder, but I'm not sure. So I double check the type of
      // builder here. It may be useless and need more investigation.
      if (builder instanceof ExtendableBuilder) {
        builder.setField(field, lazyField);
      } else {
        builder.setField(field, lazyField.getValue());
      }
    } else {
      extensions.setField(field, lazyField);
    }
  }
}
 
Example #2
Source File: AbstractMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static void mergeMessageSetExtensionFromBytes(
    ByteString rawBytes,
    ExtensionRegistry.ExtensionInfo extension,
    ExtensionRegistryLite extensionRegistry,
    Message.Builder builder,
    FieldSet<FieldDescriptor> extensions) throws IOException {

  FieldDescriptor field = extension.descriptor;
  boolean hasOriginalValue = hasOriginalMessage(builder, extensions, field);

  if (hasOriginalValue || ExtensionRegistryLite.isEagerlyParseMessageSets()) {
    // If the field already exists, we just parse the field.
    Message value = null;
    if (hasOriginalValue) {
      Message originalMessage =
          getOriginalMessage(builder, extensions, field);
      Message.Builder subBuilder= originalMessage.toBuilder();
      subBuilder.mergeFrom(rawBytes, extensionRegistry);
      value = subBuilder.buildPartial();
    } else {
      value = extension.defaultInstance.getParserForType()
          .parsePartialFrom(rawBytes, extensionRegistry);
    }
    setField(builder, extensions, field, value);
  } else {
    // Use LazyField to load MessageSet lazily.
    LazyField lazyField = new LazyField(
        extension.defaultInstance, extensionRegistry, rawBytes);
    if (builder != null) {
      // TODO(xiangl): it looks like this method can only be invoked by
      // ExtendableBuilder, but I'm not sure. So I double check the type of
      // builder here. It may be useless and need more investigation.
      if (builder instanceof ExtendableBuilder) {
        builder.setField(field, lazyField);
      } else {
        builder.setField(field, lazyField.getValue());
      }
    } else {
      extensions.setField(field, lazyField);
    }
  }
}
 
Example #3
Source File: AbstractMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static void mergeMessageSetExtensionFromBytes(
    ByteString rawBytes,
    ExtensionRegistry.ExtensionInfo extension,
    ExtensionRegistryLite extensionRegistry,
    Message.Builder builder,
    FieldSet<FieldDescriptor> extensions) throws IOException {

  FieldDescriptor field = extension.descriptor;
  boolean hasOriginalValue = hasOriginalMessage(builder, extensions, field);

  if (hasOriginalValue || ExtensionRegistryLite.isEagerlyParseMessageSets()) {
    // If the field already exists, we just parse the field.
    Message value = null;
    if (hasOriginalValue) {
      Message originalMessage =
          getOriginalMessage(builder, extensions, field);
      Message.Builder subBuilder= originalMessage.toBuilder();
      subBuilder.mergeFrom(rawBytes, extensionRegistry);
      value = subBuilder.buildPartial();
    } else {
      value = extension.defaultInstance.getParserForType()
          .parsePartialFrom(rawBytes, extensionRegistry);
    }
    setField(builder, extensions, field, value);
  } else {
    // Use LazyField to load MessageSet lazily.
    LazyField lazyField = new LazyField(
        extension.defaultInstance, extensionRegistry, rawBytes);
    if (builder != null) {
      // TODO(xiangl): it looks like this method can only be invoked by
      // ExtendableBuilder, but I'm not sure. So I double check the type of
      // builder here. It may be useless and need more investigation.
      if (builder instanceof ExtendableBuilder) {
        builder.setField(field, lazyField);
      } else {
        builder.setField(field, lazyField.getValue());
      }
    } else {
      extensions.setField(field, lazyField);
    }
  }
}