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

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

Best Java code snippets using com.google.protobuf.Message$Builder.build (Showing top 20 results out of 855)

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: 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: 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);
        }
      }
  );
}
origin: com.google.protobuf/protobuf-java

/**
 * Parse a text-format message from {@code input}.  Extensions will be
 * recognized if they are registered in {@code extensionRegistry}.
 *
 * @return the parsed message, guaranteed initialized
 */
public static <T extends Message> T parse(
  final CharSequence input,
  final ExtensionRegistry extensionRegistry,
  final Class<T> protoClass)
  throws ParseException {
 Message.Builder builder =
   Internal.getDefaultInstance(protoClass).newBuilderForType();
 merge(input, extensionRegistry, builder);
 @SuppressWarnings("unchecked")
 T output = (T) builder.build();
 return output;
}
origin: org.springframework/spring-web

@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: org.springframework/spring-web

@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);
        }
      }
  );
}
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: com.google.protobuf/protobuf-java

/**
 * Parse a text-format message from {@code input}.
 *
 * @return the parsed message, guaranteed initialized
 */
public static <T extends Message> T parse(final CharSequence input,
                     final Class<T> protoClass)
                     throws ParseException {
 Message.Builder builder =
   Internal.getDefaultInstance(protoClass).newBuilderForType();
 merge(input, builder);
 @SuppressWarnings("unchecked")
 T output = (T) builder.build();
 return output;
}
origin: googleapis/google-cloud-java

ProtoTextMatcher(Class<T> clazz, String expectedTextFormat) {
 T defaultInstance = getDefaultInstance(clazz);
 Message.Builder builder = defaultInstance.toBuilder();
 try {
  TextFormat.merge(expectedTextFormat, builder);
 } catch (TextFormat.ParseException e) {
  throw new IllegalArgumentException("Invalid text format for " + clazz.getName(), e);
 }
 @SuppressWarnings("unchecked") // T.builder().build() always returns T.
 T expectedInstance = (T) builder.build();
 expected = expectedInstance;
}
origin: apache/avro

@Override
protected Object readRecord(Object old, Schema expected,
              ResolvingDecoder in) throws IOException {
 Message.Builder b = (Message.Builder)super.readRecord(old, expected, in);
 return b.build();                             // build instance
}
origin: DozerMapper/dozer

  /**
   * {@inheritDoc}
   */
  @Override
  public Object build() {
    return internalProtoBuilder.build();
  }
}
origin: pinterest/secor

@Override
public KeyValue next() throws IOException {
  Builder messageBuilder = (Builder) reader.read();
  if (messageBuilder != null) {
    return new KeyValue(offset++, messageBuilder.build().toByteArray());
  }
  return null;
}
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

ByteBuffer buffer = this.output.asByteBuffer();
builder.mergeFrom(CodedInputStream.newInstance(buffer), extensionRegistry);
messages.add(builder.build());
DataBufferUtils.release(this.output);
this.output = null;
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: 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: 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

public static Message getRequest(Service service,
  Descriptors.MethodDescriptor methodDesc,
  org.apache.hbase.thirdparty.com.google.protobuf.ByteString shadedRequest)
throws IOException {
 Message.Builder builderForType =
   service.getRequestPrototype(methodDesc).newBuilderForType();
 org.apache.hadoop.hbase.protobuf.ProtobufUtil.mergeFrom(builderForType,
   // TODO: COPY FROM SHADED TO NON_SHADED. DO I HAVE TOO?
   shadedRequest.toByteArray());
 return builderForType.build();
}
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();
}
com.google.protobufMessage$Builderbuild

Popular methods of Message$Builder

  • mergeFrom
  • 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

  • Making http post requests using okhttp
  • scheduleAtFixedRate (ScheduledExecutorService)
  • compareTo (BigDecimal)
  • getExternalFilesDir (Context)
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • JLabel (javax.swing)
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • 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