Package com.google.protobuf
Class Protobuf
- java.lang.Object
-
- com.google.protobuf.Protobuf
-
@ExperimentalApi @CheckReturnValue final class Protobuf extends java.lang.Object
Main runtime interface for protobuf. Applications should interact with this interface (rather than directly accessing internal APIs) in order to perform operations on protobuf messages.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static booleanassumeLiteRuntimeprivate static ProtobufINSTANCEprivate java.util.concurrent.ConcurrentMap<java.lang.Class<?>,Schema<?>>schemaCacheprivate SchemaFactoryschemaFactory
-
Constructor Summary
Constructors Modifier Constructor Description privateProtobuf()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ProtobufgetInstance()Gets the singleton instance of the Protobuf runtime.(package private) intgetTotalSchemaSize()(package private) <T> booleanisInitialized(T message)Checks if all required fields are set.<T> voidmakeImmutable(T message)Marks repeated/map/extension/unknown fields as immutable.<T> voidmergeFrom(T message, Reader reader)Reads fields from the givenReaderand merges them into the message.<T> voidmergeFrom(T message, Reader reader, ExtensionRegistryLite extensionRegistry)Reads fields from the givenReaderand merges them into the message.Schema<?>registerSchema(java.lang.Class<?> messageType, Schema<?> schema)Registers the given schema for the message type only if a schema was not already registered.Schema<?>registerSchemaOverride(java.lang.Class<?> messageType, Schema<?> schema)Visible for testing only.<T> Schema<T>schemaFor(java.lang.Class<T> messageType)Gets the schema for the given message type.<T> Schema<T>schemaFor(T message)Gets the schema for the given message.<T> voidwriteTo(T message, Writer writer)Writes the given message to the targetWriter.
-
-
-
Field Detail
-
INSTANCE
private static final Protobuf INSTANCE
-
assumeLiteRuntime
static boolean assumeLiteRuntime
-
schemaFactory
private final SchemaFactory schemaFactory
-
schemaCache
private final java.util.concurrent.ConcurrentMap<java.lang.Class<?>,Schema<?>> schemaCache
-
-
Method Detail
-
getInstance
public static Protobuf getInstance()
Gets the singleton instance of the Protobuf runtime.
-
writeTo
public <T> void writeTo(T message, Writer writer) throws java.io.IOExceptionWrites the given message to the targetWriter.- Throws:
java.io.IOException
-
mergeFrom
public <T> void mergeFrom(T message, Reader reader) throws java.io.IOExceptionReads fields from the givenReaderand merges them into the message.- Throws:
java.io.IOException
-
mergeFrom
public <T> void mergeFrom(T message, Reader reader, ExtensionRegistryLite extensionRegistry) throws java.io.IOExceptionReads fields from the givenReaderand merges them into the message.- Throws:
java.io.IOException
-
makeImmutable
public <T> void makeImmutable(T message)
Marks repeated/map/extension/unknown fields as immutable.
-
isInitialized
<T> boolean isInitialized(T message)
Checks if all required fields are set.
-
schemaFor
public <T> Schema<T> schemaFor(java.lang.Class<T> messageType)
Gets the schema for the given message type.
-
schemaFor
public <T> Schema<T> schemaFor(T message)
Gets the schema for the given message.
-
registerSchema
public Schema<?> registerSchema(java.lang.Class<?> messageType, Schema<?> schema)
Registers the given schema for the message type only if a schema was not already registered.- Parameters:
messageType- the type of message on which the schema operates.schema- the schema for the message type.- Returns:
- the previously registered schema, or
nullif the given schema was successfully registered.
-
registerSchemaOverride
@CanIgnoreReturnValue public Schema<?> registerSchemaOverride(java.lang.Class<?> messageType, Schema<?> schema)
Visible for testing only. Registers the given schema for the message type. If a schema was previously registered, it will be replaced by the provided schema.- Parameters:
messageType- the type of message on which the schema operates.schema- the schema for the message type.- Returns:
- the previously registered schema, or
nullif no schema was registered previously.
-
getTotalSchemaSize
int getTotalSchemaSize()
-
-