Tabnine Logo
Message$Builder.mergeFrom
Code IndexAdd Tabnine to your IDE (free)

How to use
mergeFrom
method
in
com.google.protobuf.Message$Builder

Best Java code snippets using com.google.protobuf.Message$Builder.mergeFrom (Showing top 20 results out of 2,691)

origin: redisson/redisson

  @SuppressWarnings("unchecked")
  @Override
  public IN apply(byte[] bytes) {
    try {
      Message msg = messages.get(type);
      if(null == msg) {
        msg = (Message)type.getMethod("getDefaultInstance").invoke(null);
        messages.put(type, msg);
      }
      IN obj = (IN)msg.newBuilderForType().mergeFrom(bytes).build();
      if(null != next) {
        next.accept(obj);
        return null;
      } else {
        return obj;
      }
    } catch(Exception e) {
      throw new IllegalStateException(e.getMessage(), e);
    }
  }
};
origin: voldemort/voldemort

  public static <T extends Message.Builder> T readToBuilder(DataInputStream input, T builder)
      throws IOException {
    int size = input.readInt();
    CodedInputStream codedIn = CodedInputStream.newInstance(input);
    codedIn.pushLimit(size);
    builder.mergeFrom(codedIn);
    return builder;
  }
}
origin: com.google.protobuf/protobuf-java

private Message coerceType(Message value) {
 if (value == null) {
  return null;
 }
 if (mapEntryMessageDefaultInstance.getClass().isInstance(value)) {
  return value;
 }
 // The value is not the exact right message type.  However, if it
 // is an alternative implementation of the same type -- e.g. a
 // DynamicMessage -- we should accept it.  In this case we can make
 // a copy of the message.
 return mapEntryMessageDefaultInstance.toBuilder().mergeFrom(value).build();
}
origin: apache/hbase

public static Message getResponse(
  org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceResponse
   result,
  com.google.protobuf.Message responsePrototype)
throws IOException {
 Message response;
 if (result.getValue().hasValue()) {
  Message.Builder builder = responsePrototype.newBuilderForType();
  builder.mergeFrom(result.getValue().getValue().newInput());
  response = builder.build();
 } else {
  response = responsePrototype.getDefaultInstanceForType();
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("Master Result is value=" + response);
 }
 return response;
}
origin: apache/hbase

/**
 * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
 * buffers when working with byte arrays
 * @param builder current message builder
 * @param b byte array
 * @param offset
 * @param length
 * @throws IOException
 */
public static void mergeFrom(Message.Builder builder, byte[] b, int offset, int length)
  throws IOException {
 final CodedInputStream codedInput = CodedInputStream.newInstance(b, offset, length);
 codedInput.setSizeLimit(length);
 builder.mergeFrom(codedInput);
 codedInput.checkLastTagWas(0);
}
origin: com.google.protobuf/protobuf-java

private Object coerceType(final Object value) {
 if (type.isInstance(value)) {
  return value;
 } else {
  // The value is not the exact right message type.  However, if it
  // is an alternative implementation of the same type -- e.g. a
  // DynamicMessage -- we should accept it.  In this case we can make
  // a copy of the message.
  return ((Message.Builder) invokeOrDie(newBuilderMethod, null))
      .mergeFrom((Message) value).build();
 }
}
origin: com.google.protobuf/protobuf-java

/**
 * For internal use only.  This is to satisfy the FieldDescriptorLite
 * interface.
 */
@Override
public MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from) {
 // FieldDescriptors are only used with non-lite messages so we can just
 // down-cast and call mergeFrom directly.
 return ((Message.Builder) to).mergeFrom((Message) from);
}
origin: com.google.protobuf/protobuf-java

private Object coerceType(final Object value) {
 if (type.isInstance(value)) {
  return value;
 } else {
  // The value is not the exact right message type.  However, if it
  // is an alternative implementation of the same type -- e.g. a
  // DynamicMessage -- we should accept it.  In this case we can make
  // a copy of the message.
  return ((Message.Builder) invokeOrDie(newBuilderMethod, null))
      .mergeFrom((Message) value).buildPartial();
 }
}
origin: com.google.protobuf/protobuf-java

private Object coerceType(final Object value) {
 if (type.isInstance(value)) {
  return value;
 } else {
  // The value is not the exact right message type.  However, if it
  // is an alternative implementation of the same type -- e.g. a
  // DynamicMessage -- we should accept it.  In this case we can make
  // a copy of the message.
  return ((Message.Builder) invokeOrDie(newBuilderMethod, null))
      .mergeFrom((Message) value).buildPartial();
 }
}
origin: com.google.protobuf/protobuf-java

/**
 * Creates a new message of type "Type" which is a copy of "source".  "source"
 * must have the same descriptor but may be a different class (e.g.
 * DynamicMessage).
 */
@SuppressWarnings("unchecked")
private static <Type extends Message> Type copyAsType(
  final Type typeDefaultInstance, final Message source) {
 return (Type) typeDefaultInstance
   .newBuilderForType().mergeFrom(source).build();
}
origin: com.google.protobuf/protobuf-java

private Object coerceType(final Object value) {
 if (type.isInstance(value)) {
  return value;
 } else {
  // The value is not the exact right message type.  However, if it
  // is an alternative implementation of the same type -- e.g. a
  // DynamicMessage -- we should accept it.  In this case we can make
  // a copy of the message.
  return ((Message.Builder) invokeOrDie(newBuilderMethod, null))
      .mergeFrom((Message) value).build();
 }
}
origin: spring-projects/spring-framework

Message.Builder builder = getMessageBuilder(this.elementType.toClass());
ByteBuffer buffer = this.output.asByteBuffer();
builder.mergeFrom(CodedInputStream.newInstance(buffer), extensionRegistry);
messages.add(builder.build());
DataBufferUtils.release(this.output);
origin: osmandapp/Osmand

 /**
  * For internal use only.  This is to satisfy the FieldDescriptorLite
  * interface.
  */
 public MessageLite.Builder internalMergeFrom(
   MessageLite.Builder to, MessageLite from) {
  // FieldDescriptors are only used with non-lite messages so we can just
  // down-cast and call mergeFrom directly.
  return ((Message.Builder) to).mergeFrom((Message) from);
 }
}
origin: osmandapp/Osmand

private Object coerceType(final Object value) {
 if (type.isInstance(value)) {
  return value;
 } else {
  // The value is not the exact right message type.  However, if it
  // is an alternative implementation of the same type -- e.g. a
  // DynamicMessage -- we should accept it.  In this case we can make
  // a copy of the message.
  return ((Message.Builder) invokeOrDie(newBuilderMethod, null))
      .mergeFrom((Message) value).build();
 }
}
origin: osmandapp/Osmand

private Object coerceType(final Object value) {
 if (type.isInstance(value)) {
  return value;
 } else {
  // The value is not the exact right message type.  However, if it
  // is an alternative implementation of the same type -- e.g. a
  // DynamicMessage -- we should accept it.  In this case we can make
  // a copy of the message.
  return ((Message.Builder) invokeOrDie(newBuilderMethod, null))
      .mergeFrom((Message) value).buildPartial();
 }
}
origin: osmandapp/Osmand

/** helper method to handle {@code builder} and {@code extensions}. */
private static void mergeOriginalMessage(
  Message.Builder builder,
  FieldSet<FieldDescriptor> extensions,
  FieldDescriptor field,
  Message.Builder subBuilder) {
 Message originalMessage = getOriginalMessage(builder, extensions, field);
 if (originalMessage != null) {
  subBuilder.mergeFrom(originalMessage);
 }
}
origin: osmandapp/Osmand

/**
 * Creates a new message of type "Type" which is a copy of "source".  "source"
 * must have the same descriptor but may be a different class (e.g.
 * DynamicMessage).
 */
@SuppressWarnings("unchecked")
private static <Type extends Message> Type copyAsType(
  final Type typeDefaultInstance, final Message source) {
 return (Type)typeDefaultInstance.newBuilderForType()
                 .mergeFrom(source)
                 .build();
}
origin: apache/hbase

/**
 * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
 * buffers when working with byte arrays
 * @param builder current message builder
 * @param b byte array
 * @throws IOException
 */
public static void mergeFrom(Message.Builder builder, byte[] b) throws IOException {
 final CodedInputStream codedInput = CodedInputStream.newInstance(b);
 codedInput.setSizeLimit(b.length);
 builder.mergeFrom(codedInput);
 codedInput.checkLastTagWas(0);
}
origin: spring-projects/spring-framework

@Override
protected Message readInternal(Class<? extends Message> clazz, HttpInputMessage inputMessage)
    throws IOException, HttpMessageNotReadableException {
  MediaType contentType = inputMessage.getHeaders().getContentType();
  if (contentType == null) {
    contentType = PROTOBUF;
  }
  Charset charset = contentType.getCharset();
  if (charset == null) {
    charset = DEFAULT_CHARSET;
  }
  Message.Builder builder = getMessageBuilder(clazz);
  if (PROTOBUF.isCompatibleWith(contentType)) {
    builder.mergeFrom(inputMessage.getBody(), this.extensionRegistry);
  }
  else if (TEXT_PLAIN.isCompatibleWith(contentType)) {
    InputStreamReader reader = new InputStreamReader(inputMessage.getBody(), charset);
    TextFormat.merge(reader, this.extensionRegistry, builder);
  }
  else if (this.protobufFormatSupport != null) {
    this.protobufFormatSupport.merge(
        inputMessage.getBody(), charset, contentType, this.extensionRegistry, builder);
  }
  return builder.build();
}
origin: spring-projects/spring-framework

@Override
public Mono<Message> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType,
    @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
  return DataBufferUtils.join(inputStream).map(dataBuffer -> {
        try {
          Message.Builder builder = getMessageBuilder(elementType.toClass());
          ByteBuffer buffer = dataBuffer.asByteBuffer();
          builder.mergeFrom(CodedInputStream.newInstance(buffer), this.extensionRegistry);
          return builder.build();
        }
        catch (IOException ex) {
          throw new DecodingException("I/O error while parsing input stream", ex);
        }
        catch (Exception ex) {
          throw new DecodingException("Could not read Protobuf message: " + ex.getMessage(), ex);
        }
        finally {
          DataBufferUtils.release(dataBuffer);
        }
      }
  );
}
com.google.protobufMessage$BuildermergeFrom

Javadoc

Merge other into the message being built. other must have the exact same type as this (i.e. getDescriptorForType() == other.getDescriptorForType()). Merging occurs as follows. For each field:
* For singular primitive fields, if the field is set in other, then other's value overwrites the value in this message.
* For singular message fields, if the field is set in other, it is merged into the corresponding sub-message of this message using the same merging rules.
* For repeated fields, the elements in other are concatenated with the elements in this message. This is equivalent to the Message::MergeFrom method in C++.

Popular methods of Message$Builder

  • build
  • setField
    Sets a field to the given value. The value must be of the correct type for this field, i.e. the same
  • getDescriptorForType
    Get the message's type's descriptor. See Message#getDescriptorForType().
  • newBuilderForField
    Create a Builder for messages of the appropriate type for the given field. Messages built with this
  • addRepeatedField
    Like setRepeatedField, but appends the value as a new element.
  • clearField
    Clears the field. This is exactly equivalent to calling the generated "clear" accessor method corres
  • getDefaultInstanceForType
  • buildPartial
  • getRepeatedFieldCount
  • hasField
  • setRepeatedField
    Sets an element of a repeated field to the given value. The value must be of the correct type for th
  • getField
  • setRepeatedField,
  • getField,
  • getOneofFieldDescriptor,
  • getFieldBuilder,
  • clearOneof,
  • getRepeatedField,
  • getRepeatedFieldBuilder,
  • hasOneof,
  • mergeDelimitedFrom

Popular in Java

  • Start an intent from android
  • getSharedPreferences (Context)
  • putExtra (Intent)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • JButton (javax.swing)
  • Option (scala)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now