Interface MessageLite

    • Method Detail

      • writeTo

        void writeTo​(CodedOutputStream output)
              throws java.io.IOException
        Serializes the message and writes it to output. This does not flush or close the stream.
        Throws:
        java.io.IOException
      • getSerializedSize

        int getSerializedSize()
        Get the number of bytes required to encode this message. The result is only computed on the first call and memoized after that. If this message requires more than Integer.MAX_VALUE bytes to encode, the return value will be smaller than the actual number of bytes required and might be negative.
      • getParserForType

        Parser<? extends MessageLite> getParserForType()
        Gets the parser for a message of the same type as this message.
      • toByteString

        ByteString toByteString()
        Serializes the message to a ByteString and returns it. This is just a trivial wrapper around writeTo(CodedOutputStream). If this message requires more than Integer.MAX_VALUE bytes to encode, the behavior is unpredictable. It may throw a runtime exception or truncate or slice the data.
      • toByteArray

        byte[] toByteArray()
        Serializes the message to a byte array and returns it. This is just a trivial wrapper around writeTo(CodedOutputStream). If this message requires more than Integer.MAX_VALUE bytes to encode, the behavior is unpredictable. It may throw a runtime exception or truncate or slice the data.
      • writeTo

        void writeTo​(java.io.OutputStream output)
              throws java.io.IOException
        Serializes the message and writes it to output. This is just a trivial wrapper around 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, for instance, by writing the size of the message before the data, then making sure to limit the input to that size on the receiving end by wrapping the InputStream in one which limits the input. Alternatively, just use writeDelimitedTo(OutputStream).

        Throws:
        java.io.IOException
      • writeDelimitedTo

        void writeDelimitedTo​(java.io.OutputStream output)
                       throws java.io.IOException
        Like 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 MessageLite.Builder.mergeDelimitedFrom(InputStream) (or the static method YourMessageType.parseDelimitedFrom(InputStream)) to parse messages written by this method.
        Throws:
        java.io.IOException
      • newBuilderForType

        MessageLite.Builder newBuilderForType()
        Constructs a new builder for a message of the same type as this message.
      • toBuilder

        MessageLite.Builder toBuilder()
        Constructs a builder initialized with the current message. Use this to derive a new message from the current one.