Class Protobuf
java.lang.Object
com.google.protobuf.Protobuf
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
FieldsModifier and TypeFieldDescriptionprivate static final Protobufprivate final ConcurrentMap<Class<?>, Schema<?>> private final SchemaFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ProtobufGets the singleton instance of the Protobuf runtime.(package private) int(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> voidReads 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(Class<?> messageType, Schema<?> schema) Registers the given schema for the message type only if a schema was not already registered.Schema<?> registerSchemaOverride(Class<?> messageType, Schema<?> schema) Visible for testing only.<T> Schema<T> Gets the schema for the given message type.<T> Schema<T> schemaFor(T message) Gets the schema for the given message.<T> voidWrites the given message to the targetWriter.
-
Field Details
-
INSTANCE
-
schemaFactory
-
schemaCache
-
-
Constructor Details
-
Protobuf
private Protobuf()
-
-
Method Details
-
getInstance
Gets the singleton instance of the Protobuf runtime. -
writeTo
Writes the given message to the targetWriter.- Throws:
IOException
-
mergeFrom
Reads fields from the givenReaderand merges them into the message.- Throws:
IOException
-
mergeFrom
public <T> void mergeFrom(T message, Reader reader, ExtensionRegistryLite extensionRegistry) throws IOException Reads fields from the givenReaderand merges them into the message.- Throws:
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
-
schemaFor
Gets the schema for the given message. -
registerSchema
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(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()
-