public abstract class ProtoMessage<MessageType extends ProtoMessage<?>> extends Object
API partially copied from Google's MessageNano
| Modifier and Type | Field and Description |
|---|---|
protected int |
bitField0_ |
protected int |
cachedSize |
protected static FieldName |
unknownBytesFieldName
JSON field name for serializing unknown bytes.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ProtoMessage() |
| Modifier and Type | Method and Description |
|---|---|
protected static byte[] |
bytesDefaultValue(String bytes)
Helper to determine the default value for 'Bytes' fields.
|
MessageType |
checkInitialized()
Helper method to check if this message is initialized, i.e.,
if all required fields are set.
|
abstract MessageType |
clear()
Sets all fields and data to their default values.
|
MessageType |
clearQuick()
Clears all has state so that the message would serialize empty,
but does not set field default values and does not get rid of
memory that was allocated for repeated types.
|
abstract MessageType |
clone()
Creates a new instance of this message with the same content
|
protected abstract int |
computeSerializedSize()
Computes the number of bytes required to encode this message.
|
abstract MessageType |
copyFrom(MessageType other)
Copies all fields and data from another message of the same
type into this message.
|
abstract boolean |
equals(Object obj)
Indicates whether another object is "equal to" this one.
|
int |
getCachedSize()
Get the number of bytes required to encode this message.
|
List<String> |
getMissingFields() |
protected void |
getMissingFields(String prefix,
List<String> results)
Adds the full path to all missing required fields in the message
|
protected static void |
getMissingFields(String prefix,
String fieldName,
ProtoMessage<?> field,
List<String> results) |
protected static void |
getMissingFields(String prefix,
String fieldName,
RepeatedMessage<?> field,
List<String> results) |
int |
getSerializedSize()
Computes the number of bytes required to encode this message.
|
RepeatedByte |
getUnknownBytes() |
int |
hashCode()
Messages have no immutable state and should not
be used in hashing structures.
|
boolean |
isEmpty() |
boolean |
isInitialized() |
MessageType |
mergeDelimitedFrom(ProtoSource input)
Merges the contents for one message written in length delimited form.
|
MessageType |
mergeFrom(JsonSource input)
Parse
input as a message of this type and merge it with the
message being built. |
MessageType |
mergeFrom(MessageType other)
Merge
other into the message being built. |
abstract MessageType |
mergeFrom(ProtoSource input)
Parse
input as a message of this type and merge it with the
message being built. |
static <T extends ProtoMessage<T>> |
mergeFrom(T msg,
byte[] data)
Parse
data as a message of this type and merge it with the message being built. |
static <T extends ProtoMessage<T>> |
mergeFrom(T msg,
byte[] data,
int off,
int len)
Parse
data as a message of this type and merge it with the message being built. |
static <T extends ProtoMessage<T>> |
mergeFrom(T msg,
JsonSource input)
Parse
input as a message of this type and merge it with the message being built. |
static <T extends ProtoMessage<T>> |
mergeFrom(T msg,
ProtoSource input)
Parse
input as a message of this type and merge it with the message being built. |
protected UninitializedMessageException |
rethrowFromParent(UninitializedMessageException ex) |
byte[] |
toByteArray()
Serialize to a byte array.
|
static byte[] |
toByteArray(ProtoMessage<?> msg)
Serialize to a byte array.
|
static void |
toByteArray(ProtoMessage<?> msg,
byte[] data,
int offset,
int length)
Serialize to a byte array starting at offset through length.
|
String |
toString()
Returns a string that contains a human-readable representation of the contents.
|
MessageType |
writeDelimitedTo(ProtoSink output)
Serializes the message and writes it to the
output in
length delimited form. |
void |
writeTo(JsonSink output)
Serializes this message in a JSON format compatible with
https://developers.google.com/protocol-buffers/docs/proto3#json.
|
abstract void |
writeTo(ProtoSink output)
Serializes the message and writes it to
output. |
protected int cachedSize
protected int bitField0_
protected static final FieldName unknownBytesFieldName
public abstract MessageType copyFrom(MessageType other)
other - message with the contents to be copiedpublic abstract MessageType clear()
public MessageType clearQuick()
Use this if you use this message for serialization purposes or if you do not require default values for unset fields.
public boolean isEmpty()
public boolean isInitialized()
public final MessageType checkInitialized() throws InvalidProtocolBufferException
Message content is not automatically checked after merging new data. This method should be called manually as needed.
InvalidProtocolBufferException - if it is not initialized.public int getCachedSize()
public int getSerializedSize()
protected abstract int computeSerializedSize()
public abstract void writeTo(ProtoSink output) throws IOException
output.output - the output to receive the serialized form.IOException - if an error occurred writing to output.public MessageType writeDelimitedTo(ProtoSink output) throws IOException
output in
length delimited form.IOExceptionpublic MessageType mergeDelimitedFrom(ProtoSource input) throws IOException
IOExceptionpublic abstract MessageType mergeFrom(ProtoSource input) throws IOException
input as a message of this type and merge it with the
message being built.IOExceptionpublic MessageType mergeFrom(MessageType other)
other into the message being built. other must have the exact same type
as this.
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.
* For oneof groups, if the other message has one of the fields set, the group of this message
is cleared and replaced by the field of the other message, so that the oneof constraint is
preserved.
This is equivalent to the Message::MergeFrom method in C++.
public void writeTo(JsonSink output) throws IOException
The implementation may not fail on missing required fields, so
required fields would need to be checked using isInitialized().
output - json sinkIOExceptionpublic MessageType mergeFrom(JsonSource input) throws IOException
input as a message of this type and merge it with the
message being built.IOExceptionpublic final byte[] toByteArray()
public static byte[] toByteArray(ProtoMessage<?> msg)
public static void toByteArray(ProtoMessage<?> msg, byte[] data, int offset, int length)
public static <T extends ProtoMessage<T>> T mergeFrom(T msg, byte[] data) throws InvalidProtocolBufferException
data as a message of this type and merge it with the message being built.InvalidProtocolBufferExceptionpublic static <T extends ProtoMessage<T>> T mergeFrom(T msg, byte[] data, int off, int len) throws InvalidProtocolBufferException
data as a message of this type and merge it with the message being built.InvalidProtocolBufferExceptionpublic static <T extends ProtoMessage<T>> T mergeFrom(T msg, ProtoSource input) throws IOException
input as a message of this type and merge it with the message being built.IOExceptionpublic static <T extends ProtoMessage<T>> T mergeFrom(T msg, JsonSource input) throws IOException
input as a message of this type and merge it with the message being built.IOExceptionpublic abstract boolean equals(Object obj)
An object is considered equal when it is of the same message type, contains the same fields (same has state), and all the field contents are equal.
This comparison ignores unknown fields, so the serialized binary form may not be equal.
public final int hashCode()
public String toString()
public abstract MessageType clone()
public List<String> getMissingFields()
protected void getMissingFields(String prefix, List<String> results)
protected static void getMissingFields(String prefix, String fieldName, ProtoMessage<?> field, List<String> results)
protected static void getMissingFields(String prefix, String fieldName, RepeatedMessage<?> field, List<String> results)
protected UninitializedMessageException rethrowFromParent(UninitializedMessageException ex)
protected static byte[] bytesDefaultValue(String bytes)
public RepeatedByte getUnknownBytes()
Copyright © 2019–2024 HEBI Robotics. All rights reserved.