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

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

Best Java code snippets using com.google.protobuf.Message$Builder.getDefaultInstanceForType (Showing top 10 results out of 315)

origin: sixt/ja-micro

  return (TYPE) getBuilder(messageClass).getDefaultInstanceForType();
} catch (Exception e) {
  logger.warn("Error building protobuf object of type {} from json: {}",
origin: org.apache.crunch/crunch

/**
 * Utility function for creating a default PB Messgae from a Class object that
 * works with both protoc 2.3.0 and 2.4.x.
 * @param clazz The class of the protocol buffer to create
 * @return An instance of a protocol buffer
 */
public static <M extends Message> M getDefaultInstance(Class<M> clazz) {
 if (clazz.getConstructors().length > 0) {
  // Protobuf 2.3.0
  return ReflectionUtils.newInstance(clazz, null);
 } else {
  // Protobuf 2.4.x
  try {
   Message.Builder mb = (Message.Builder) clazz.getDeclaredMethod("newBuilder").invoke(null);
   return (M) mb.getDefaultInstanceForType();
  } catch (Exception e) {
   throw new CrunchRuntimeException(e);
  }  
 }
}

origin: org.apache.crunch/crunch-core

/**
 * Utility function for creating a default PB Messgae from a Class object that
 * works with both protoc 2.3.0 and 2.4.x.
 * @param clazz The class of the protocol buffer to create
 * @return An instance of a protocol buffer
 */
public static <M extends Message> M getDefaultInstance(Class<M> clazz) {
 if (clazz.getConstructors().length > 0) {
  // Protobuf 2.3.0
  return ReflectionUtils.newInstance(clazz, null);
 } else {
  // Protobuf 2.4.x
  try {
   Message.Builder mb = (Message.Builder) clazz.getDeclaredMethod("newBuilder").invoke(null);
   return (M) mb.getDefaultInstanceForType();
  } catch (Exception e) {
   throw new CrunchRuntimeException(e);
  }  
 }
}

origin: com.hubspot.jackson/jackson-datatype-protobuf

 subMessageType = defaultInstance.getClass();
} else {
 subMessageType = builder.newBuilderForField(field).getDefaultInstanceForType().getClass();
origin: com.hubspot.jackson/jackson-datatype-protobuf

private JsonDeserializer<Object> getMessageDeserializer(
    Message.Builder builder,
    FieldDescriptor field,
    Message defaultInstance,
    DeserializationContext context
) throws IOException {
 JsonDeserializer<Object> deserializer = deserializerCache.get(field);
 if (deserializer == null) {
  final Class<?> subType;
  if (defaultInstance == null) {
   Message.Builder subBuilder = builder.newBuilderForField(field);
   subType = subBuilder.getDefaultInstanceForType().getClass();
  } else {
   subType = defaultInstance.getClass();
  }
  JavaType type = context.constructType(subType);
  deserializer = context.findContextualValueDeserializer(type, null);
  deserializerCache.put(field, deserializer);
 }
 return deserializer;
}
origin: com.github.jiayuhan-it/hadoop-common

/**
 * Decode the a protobuf from the given input stream 
 * @param builder - Builder of the protobuf to decode
 * @param dis - DataInputStream to read the protobuf
 * @return Message - decoded protobuf
 * @throws WrappedRpcServerException - deserialization failed
 */
@SuppressWarnings("unchecked")
private <T extends Message> T decodeProtobufFromStream(Builder builder,
  DataInputStream dis) throws WrappedRpcServerException {
 try {
  builder.mergeDelimitedFrom(dis);
  return (T)builder.build();
 } catch (Exception ioe) {
  Class<?> protoClass = builder.getDefaultInstanceForType().getClass();
  throw new WrappedRpcServerException(
    RpcErrorCodeProto.FATAL_DESERIALIZING_REQUEST,
    "Error decoding " + protoClass.getSimpleName() + ": "+ ioe);
 }
}
origin: ch.cern.hadoop/hadoop-common

/**
 * Decode the a protobuf from the given input stream 
 * @param builder - Builder of the protobuf to decode
 * @param dis - DataInputStream to read the protobuf
 * @return Message - decoded protobuf
 * @throws WrappedRpcServerException - deserialization failed
 */
@SuppressWarnings("unchecked")
private <T extends Message> T decodeProtobufFromStream(Builder builder,
  DataInputStream dis) throws WrappedRpcServerException {
 try {
  builder.mergeDelimitedFrom(dis);
  return (T)builder.build();
 } catch (Exception ioe) {
  Class<?> protoClass = builder.getDefaultInstanceForType().getClass();
  throw new WrappedRpcServerException(
    RpcErrorCodeProto.FATAL_DESERIALIZING_REQUEST,
    "Error decoding " + protoClass.getSimpleName() + ": "+ ioe);
 }
}
origin: com.github.protobufel/protobufel

/**
 * Clears the value of the field.
 *
 * @return the builder
 */
@Override
@SuppressWarnings("unchecked")
public void clear() {
 message =
   (MType) (message != null ? message.getDefaultInstanceForType() : builder
     .getDefaultInstanceForType());
 if (builder != null) {
  dispose(builder);
  builder = null;
 }
 onChanged();
}
origin: xyz.codemeans.protobuf4j/protobuf4j-core

@SuppressWarnings("unchecked")
@Override
public T defaultValue() {
 return (T) internalBuilder.getDefaultInstanceForType();
}
origin: com.twitter.elephantbird/elephant-bird-core

@SuppressWarnings("unchecked")
public M fromBytes(byte[] messageBuffer, int offset, int len)
  throws InvalidProtocolBufferException, UninitializedMessageException {
 if (defaultInstance == null) {
  defaultInstance = Protobufs.getMessageBuilder(typeRef.getRawClass())
                .getDefaultInstanceForType();
 }
 return (M) defaultInstance.newBuilderForType()
              .mergeFrom(messageBuffer, offset, len)
              .build();
}
com.google.protobufMessage$BuildergetDefaultInstanceForType

Popular methods of Message$Builder

  • build
  • 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
  • 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 requests using okhttp
  • onRequestPermissionsResult (Fragment)
  • setContentView (Activity)
  • scheduleAtFixedRate (Timer)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • JPanel (javax.swing)
  • Best IntelliJ plugins
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