com.google.protobuf
Class AbstractMessage

java.lang.Object
  extended by com.google.protobuf.AbstractMessage
All Implemented Interfaces:
Message
Direct Known Subclasses:
DynamicMessage, GeneratedMessage

public abstract class AbstractMessage
extends java.lang.Object
implements Message

A partial implementation of the Message interface which implements as many methods of that interface as possible in terms of other methods.

Author:
[email protected] Kenton Varda

Nested Class Summary
static class AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder>
          A partial implementation of the Message.Builder interface which implements as many methods of that interface as possible in terms of other methods.
 
Constructor Summary
AbstractMessage()
           
 
Method Summary
 boolean equals(java.lang.Object other)
          Compares the specified object with this message for equality.
 int getSerializedSize()
          Get the number of bytes required to encode this message.
 int hashCode()
          Returns the hash code value for this message.
 boolean isInitialized()
          Returns true if all required fields in the message and all embedded messages are set, false otherwise.
 byte[] toByteArray()
          Serializes the message to a byte array and returns it.
 ByteString toByteString()
          Serializes the message to a ByteString and returns it.
 java.lang.String toString()
          Converts the message to a string in protocol buffer text format.
 void writeDelimitedTo(java.io.OutputStream output)
          Like Message.writeTo(OutputStream), but writes the size of the message as a varint before writing the data.
 void writeTo(CodedOutputStream output)
          Serializes the message and writes it to output.
 void writeTo(java.io.OutputStream output)
          Serializes the message and writes it to output.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.protobuf.Message
getAllFields, getDefaultInstanceForType, getDescriptorForType, getField, getRepeatedField, getRepeatedFieldCount, getUnknownFields, hasField, newBuilderForType, toBuilder
 

Constructor Detail

AbstractMessage

public AbstractMessage()
Method Detail

isInitialized

public boolean isInitialized()
Description copied from interface: Message
Returns true if all required fields in the message and all embedded messages are set, false otherwise.

Specified by:
isInitialized in interface Message

toString

public final java.lang.String toString()
Description copied from interface: Message
Converts the message to a string in protocol buffer text format. This is just a trivial wrapper around TextFormat.printToString(Message).

Specified by:
toString in interface Message
Overrides:
toString in class java.lang.Object

writeTo

public void writeTo(CodedOutputStream output)
             throws java.io.IOException
Description copied from interface: Message
Serializes the message and writes it to output. This does not flush or close the stream.

Specified by:
writeTo in interface Message
Throws:
java.io.IOException

toByteString

public ByteString toByteString()
Description copied from interface: Message
Serializes the message to a ByteString and returns it. This is just a trivial wrapper around Message.writeTo(CodedOutputStream).

Specified by:
toByteString in interface Message

toByteArray

public byte[] toByteArray()
Description copied from interface: Message
Serializes the message to a byte array and returns it. This is just a trivial wrapper around Message.writeTo(CodedOutputStream).

Specified by:
toByteArray in interface Message

writeTo

public void writeTo(java.io.OutputStream output)
             throws java.io.IOException
Description copied from interface: Message
Serializes the message and writes it to output. This is just a trivial wrapper around Message.writeTo(CodedOutputStream). This does not flush or close the stream.

NOTE: Protocol Buffers are not self-delimiting. Therefore, if you write any more data to the stream after the message, you must somehow ensure that the parser on the receiving end does not interpret this as being part of the protocol message. This can be done e.g. by writing the size of the message before the data, then making sure to limit the input to that size on the receiving end (e.g. by wrapping the InputStream in one which limits the input). Alternatively, just use Message.writeDelimitedTo(OutputStream).

Specified by:
writeTo in interface Message
Throws:
java.io.IOException

writeDelimitedTo

public void writeDelimitedTo(java.io.OutputStream output)
                      throws java.io.IOException
Description copied from interface: Message
Like Message.writeTo(OutputStream), but writes the size of the message as a varint before writing the data. This allows more data to be written to the stream after the message without the need to delimit the message data yourself. Use Message.Builder.mergeDelimitedFrom(InputStream) (or the static method YourMessageType.parseDelimitedFrom(InputStream)) to parse messages written by this method.

Specified by:
writeDelimitedTo in interface Message
Throws:
java.io.IOException

getSerializedSize

public int getSerializedSize()
Description copied from interface: Message
Get the number of bytes required to encode this message. The result is only computed on the first call and memoized after that.

Specified by:
getSerializedSize in interface Message

equals

public boolean equals(java.lang.Object other)
Description copied from interface: Message
Compares the specified object with this message for equality. Returns true if the given object is a message of the same type (as defined by getDescriptorForType()) and has identical values for all of its fields.

Specified by:
equals in interface Message
Overrides:
equals in class java.lang.Object
Parameters:
other - object to be compared for equality with this message
Returns:
true if the specified object is equal to this message

hashCode

public int hashCode()
Description copied from interface: Message
Returns the hash code value for this message. The hash code of a message is defined to be getDescriptor().hashCode() ^ map.hashCode(), where map is a map of field numbers to field values.

Specified by:
hashCode in interface Message
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value for this message
See Also:
Map.hashCode()


Copyright © 2008-2009. All Rights Reserved.