Class CodedOutputStream

java.lang.Object
com.google.protobuf.ByteOutput
com.google.protobuf.CodedOutputStream
Direct Known Subclasses:
CodedOutputStream.AbstractBufferedEncoder, CodedOutputStream.ArrayEncoder, CodedOutputStream.SafeDirectNioEncoder, CodedOutputStream.UnsafeDirectNioEncoder

public abstract class CodedOutputStream extends ByteOutput
Encodes and writes protocol message fields.

This class contains two kinds of methods: methods that write specific protocol message constructs and field types (e.g. writeTag(int, int) and writeInt32(int, int)) and methods that write low-level values (e.g. writeRawVarint32(int) and writeRawBytes(byte[])). If you are writing encoded protocol messages, you should use the former methods, but if you are writing some other format of your own design, use the latter.

This class is totally unsynchronized.

  • Field Details

  • Constructor Details

    • CodedOutputStream

      private CodedOutputStream()
  • Method Details

    • computePreferredBufferSize

      static int computePreferredBufferSize(int dataLength)
      Returns the buffer size to efficiently write dataLength bytes to this CodedOutputStream. Used by AbstractMessageLite.
      Returns:
      the buffer size to efficiently write dataLength bytes to this CodedOutputStream.
    • newInstance

      public static CodedOutputStream newInstance(OutputStream output)
      Create a new CodedOutputStream wrapping the given OutputStream.

      NOTE: The provided OutputStream MUST NOT retain access or modify the provided byte arrays. Doing so may result in corrupted data, which would be difficult to debug.

    • newInstance

      public static CodedOutputStream newInstance(OutputStream output, int bufferSize)
      Create a new CodedOutputStream wrapping the given OutputStream with a given buffer size.

      NOTE: The provided OutputStream MUST NOT retain access or modify the provided byte arrays. Doing so may result in corrupted data, which would be difficult to debug.

    • newInstance

      public static CodedOutputStream newInstance(byte[] flatArray)
      Create a new CodedOutputStream that writes directly to the given byte array. If more bytes are written than fit in the array, CodedOutputStream.OutOfSpaceException will be thrown. Writing directly to a flat array is faster than writing to an OutputStream. See also ByteString.newCodedBuilder(int).
    • newInstance

      public static CodedOutputStream newInstance(byte[] flatArray, int offset, int length)
      Create a new CodedOutputStream that writes directly to the given byte array slice. If more bytes are written than fit in the slice, CodedOutputStream.OutOfSpaceException will be thrown. Writing directly to a flat array is faster than writing to an OutputStream. See also ByteString.newCodedBuilder(int).
    • newInstance

      public static CodedOutputStream newInstance(ByteBuffer buffer)
      Create a new CodedOutputStream that writes to the given ByteBuffer.
    • newUnsafeInstance

      static CodedOutputStream newUnsafeInstance(ByteBuffer buffer)
      For testing purposes only.
    • newSafeInstance

      static CodedOutputStream newSafeInstance(ByteBuffer buffer)
      For testing purposes only.
    • useDeterministicSerialization

      public void useDeterministicSerialization()
      Configures serialization to be deterministic.

      The deterministic serialization guarantees that for a given binary, equal (defined by the equals() methods in protos) messages will always be serialized to the same bytes. This implies:

      • repeated serialization of a message will return the same bytes
      • different processes of the same binary (which may be executing on different machines) will serialize equal messages to the same bytes.

      Note the deterministic serialization is NOT canonical across languages; it is also unstable across different builds with schema changes due to unknown fields. Users who need canonical serialization, e.g. persistent storage in a canonical form, fingerprinting, etc, should define their own canonicalization specification and implement the serializer using reflection APIs rather than relying on this API.

      Once set, the serializer will: (Note this is an implementation detail and may subject to change in the future)

      • sort map entries by keys in lexicographical order or numerical order. Note: For string keys, the order is based on comparing the Unicode value of each character in the strings. The order may be different from the deterministic serialization in other languages where maps are sorted on the lexicographical order of the UTF8 encoded keys.
    • isSerializationDeterministic

      boolean isSerializationDeterministic()
    • newInstance

      @Deprecated public static CodedOutputStream newInstance(ByteBuffer byteBuffer, int unused)
      Deprecated.
      the size parameter is no longer used since use of an internal buffer is useless (and wasteful) when writing to a ByteBuffer. Use newInstance(ByteBuffer) instead.
      Create a new CodedOutputStream that writes to the given ByteBuffer.
    • newInstance

      static CodedOutputStream newInstance(ByteOutput byteOutput, int bufferSize)
      Create a new CodedOutputStream that writes to the provided ByteOutput.

      NOTE: The ByteOutput MUST NOT modify the provided buffers. Doing so may result in corrupted data, which would be difficult to debug.

      Parameters:
      byteOutput - the output target for encoded bytes.
      bufferSize - the size of the internal scratch buffer to be used for string encoding. Setting this to 0 will disable buffering, requiring an allocation for each encoded string.
    • writeTag

      public abstract void writeTag(int fieldNumber, int wireType) throws IOException
      Encode and write a tag.
      Throws:
      IOException
    • writeInt32

      public abstract void writeInt32(int fieldNumber, int value) throws IOException
      Write an int32 field, including tag, to the stream.
      Throws:
      IOException
    • writeUInt32

      public abstract void writeUInt32(int fieldNumber, int value) throws IOException
      Write a uint32 field, including tag, to the stream.
      Throws:
      IOException
    • writeSInt32

      public final void writeSInt32(int fieldNumber, int value) throws IOException
      Write a sint32 field, including tag, to the stream.
      Throws:
      IOException
    • writeFixed32

      public abstract void writeFixed32(int fieldNumber, int value) throws IOException
      Write a fixed32 field, including tag, to the stream.
      Throws:
      IOException
    • writeSFixed32

      public final void writeSFixed32(int fieldNumber, int value) throws IOException
      Write an sfixed32 field, including tag, to the stream.
      Throws:
      IOException
    • writeInt64

      public final void writeInt64(int fieldNumber, long value) throws IOException
      Write an int64 field, including tag, to the stream.
      Throws:
      IOException
    • writeUInt64

      public abstract void writeUInt64(int fieldNumber, long value) throws IOException
      Write a uint64 field, including tag, to the stream.
      Throws:
      IOException
    • writeSInt64

      public final void writeSInt64(int fieldNumber, long value) throws IOException
      Write an sint64 field, including tag, to the stream.
      Throws:
      IOException
    • writeFixed64

      public abstract void writeFixed64(int fieldNumber, long value) throws IOException
      Write a fixed64 field, including tag, to the stream.
      Throws:
      IOException
    • writeSFixed64

      public final void writeSFixed64(int fieldNumber, long value) throws IOException
      Write an sfixed64 field, including tag, to the stream.
      Throws:
      IOException
    • writeFloat

      public final void writeFloat(int fieldNumber, float value) throws IOException
      Write a float field, including tag, to the stream.
      Throws:
      IOException
    • writeDouble

      public final void writeDouble(int fieldNumber, double value) throws IOException
      Write a double field, including tag, to the stream.
      Throws:
      IOException
    • writeBool

      public abstract void writeBool(int fieldNumber, boolean value) throws IOException
      Write a bool field, including tag, to the stream.
      Throws:
      IOException
    • writeEnum

      public final void writeEnum(int fieldNumber, int value) throws IOException
      Write an enum field, including tag, to the stream. The provided value is the numeric value used to represent the enum value on the wire (not the enum ordinal value).
      Throws:
      IOException
    • writeString

      public abstract void writeString(int fieldNumber, String value) throws IOException
      Write a string field, including tag, to the stream.
      Throws:
      IOException
    • writeBytes

      public abstract void writeBytes(int fieldNumber, ByteString value) throws IOException
      Write a bytes field, including tag, to the stream.
      Throws:
      IOException
    • writeByteArray

      public abstract void writeByteArray(int fieldNumber, byte[] value) throws IOException
      Write a bytes field, including tag, to the stream.
      Throws:
      IOException
    • writeByteArray

      public abstract void writeByteArray(int fieldNumber, byte[] value, int offset, int length) throws IOException
      Write a bytes field, including tag, to the stream.
      Throws:
      IOException
    • writeByteBuffer

      public abstract void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException
      Write a bytes field, including tag, to the stream. This method will write all content of the ByteBuffer regardless of the current position and limit (i.e., the number of bytes to be written is value.capacity(), not value.remaining()). Furthermore, this method doesn't alter the state of the passed-in ByteBuffer. Its position, limit, mark, etc. will remain unchanged. If you only want to write the remaining bytes of a ByteBuffer, you can call writeByteBuffer(fieldNumber, byteBuffer.slice()).
      Throws:
      IOException
    • writeRawByte

      public final void writeRawByte(byte value) throws IOException
      Write a single byte.
      Throws:
      IOException
    • writeRawByte

      public final void writeRawByte(int value) throws IOException
      Write a single byte, represented by an integer value.
      Throws:
      IOException
    • writeRawBytes

      public final void writeRawBytes(byte[] value) throws IOException
      Write an array of bytes.
      Throws:
      IOException
    • writeRawBytes

      public final void writeRawBytes(byte[] value, int offset, int length) throws IOException
      Write part of an array of bytes.
      Throws:
      IOException
    • writeRawBytes

      public final void writeRawBytes(ByteString value) throws IOException
      Write a byte string.
      Throws:
      IOException
    • writeRawBytes

      public abstract void writeRawBytes(ByteBuffer value) throws IOException
      Write a ByteBuffer. This method will write all content of the ByteBuffer regardless of the current position and limit (i.e., the number of bytes to be written is value.capacity(), not value.remaining()). Furthermore, this method doesn't alter the state of the passed-in ByteBuffer. Its position, limit, mark, etc. will remain unchanged. If you only want to write the remaining bytes of a ByteBuffer, you can call writeRawBytes(byteBuffer.slice()).
      Throws:
      IOException
    • writeMessage

      public abstract void writeMessage(int fieldNumber, MessageLite value) throws IOException
      Write an embedded message field, including tag, to the stream.
      Throws:
      IOException
    • writeMessage

      abstract void writeMessage(int fieldNumber, MessageLite value, Schema schema) throws IOException
      Write an embedded message field, including tag, to the stream.
      Throws:
      IOException
    • writeMessageSetExtension

      public abstract void writeMessageSetExtension(int fieldNumber, MessageLite value) throws IOException
      Write a MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.
      Throws:
      IOException
    • writeRawMessageSetExtension

      public abstract void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws IOException
      Write an unparsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.
      Throws:
      IOException
    • writeInt32NoTag

      public abstract void writeInt32NoTag(int value) throws IOException
      Write an int32 field to the stream.
      Throws:
      IOException
    • writeUInt32NoTag

      public abstract void writeUInt32NoTag(int value) throws IOException
      Write a uint32 field to the stream.
      Throws:
      IOException
    • writeSInt32NoTag

      public final void writeSInt32NoTag(int value) throws IOException
      Write a sint32 field to the stream.
      Throws:
      IOException
    • writeFixed32NoTag

      public abstract void writeFixed32NoTag(int value) throws IOException
      Write a fixed32 field to the stream.
      Throws:
      IOException
    • writeSFixed32NoTag

      public final void writeSFixed32NoTag(int value) throws IOException
      Write a sfixed32 field to the stream.
      Throws:
      IOException
    • writeInt64NoTag

      public final void writeInt64NoTag(long value) throws IOException
      Write an int64 field to the stream.
      Throws:
      IOException
    • writeUInt64NoTag

      public abstract void writeUInt64NoTag(long value) throws IOException
      Write a uint64 field to the stream.
      Throws:
      IOException
    • writeSInt64NoTag

      public final void writeSInt64NoTag(long value) throws IOException
      Write a sint64 field to the stream.
      Throws:
      IOException
    • writeFixed64NoTag

      public abstract void writeFixed64NoTag(long value) throws IOException
      Write a fixed64 field to the stream.
      Throws:
      IOException
    • writeSFixed64NoTag

      public final void writeSFixed64NoTag(long value) throws IOException
      Write a sfixed64 field to the stream.
      Throws:
      IOException
    • writeFloatNoTag

      public final void writeFloatNoTag(float value) throws IOException
      Write a float field to the stream.
      Throws:
      IOException
    • writeDoubleNoTag

      public final void writeDoubleNoTag(double value) throws IOException
      Write a double field to the stream.
      Throws:
      IOException
    • writeBoolNoTag

      public final void writeBoolNoTag(boolean value) throws IOException
      Write a bool field to the stream.
      Throws:
      IOException
    • writeEnumNoTag

      public final void writeEnumNoTag(int value) throws IOException
      Write an enum field to the stream. The provided value is the numeric value used to represent the enum value on the wire (not the enum ordinal value).
      Throws:
      IOException
    • writeStringNoTag

      public abstract void writeStringNoTag(String value) throws IOException
      Write a string field to the stream.
      Throws:
      IOException
    • writeBytesNoTag

      public abstract void writeBytesNoTag(ByteString value) throws IOException
      Write a bytes field to the stream.
      Throws:
      IOException
    • writeByteArrayNoTag

      public final void writeByteArrayNoTag(byte[] value) throws IOException
      Write a bytes field to the stream.
      Throws:
      IOException
    • writeMessageNoTag

      public abstract void writeMessageNoTag(MessageLite value) throws IOException
      Write an embedded message field to the stream.
      Throws:
      IOException
    • writeMessageNoTag

      abstract void writeMessageNoTag(MessageLite value, Schema schema) throws IOException
      Write an embedded message field to the stream.
      Throws:
      IOException
    • write

      @ExperimentalApi public abstract void write(byte value) throws IOException
      Description copied from class: ByteOutput
      Writes a single byte.
      Specified by:
      write in class ByteOutput
      Parameters:
      value - the byte to be written
      Throws:
      IOException - thrown if an error occurred while writing
    • write

      @ExperimentalApi public abstract void write(byte[] value, int offset, int length) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The ByteOutput must copy value if it will not be processed prior to the return of this method call, since value may be reused/altered by the caller.

      NOTE: This method MUST NOT modify the value. Doing so is a programming error and will lead to data corruption which will be difficult to debug.

      Specified by:
      write in class ByteOutput
      Parameters:
      value - the bytes to be written
      offset - the offset of the start of the writable range
      length - the number of bytes to write starting from offset
      Throws:
      IOException - thrown if an error occurred while writing
    • writeLazy

      @ExperimentalApi public abstract void writeLazy(byte[] value, int offset, int length) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The ByteOutput is free to retain a reference to the value beyond the scope of this method call (e.g. write later) since it is considered immutable and is guaranteed not to change by the caller.

      NOTE: This method MUST NOT modify the value. Doing so is a programming error and will lead to data corruption which will be difficult to debug.

      Specified by:
      writeLazy in class ByteOutput
      Parameters:
      value - the bytes to be written
      offset - the offset of the start of the writable range
      length - the number of bytes to write starting from offset
      Throws:
      IOException - thrown if an error occurred while writing
    • write

      public abstract void write(ByteBuffer value) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The ByteOutput must copy value if it will not be processed prior to the return of this method call, since value may be reused/altered by the caller.

      NOTE: This method MUST NOT modify the value. Doing so is a programming error and will lead to data corruption which will be difficult to debug.

      Specified by:
      write in class ByteOutput
      Parameters:
      value - the bytes to be written. Upon returning from this call, the position of this buffer will be set to the limit
      Throws:
      IOException - thrown if an error occurred while writing
    • writeLazy

      @ExperimentalApi public abstract void writeLazy(ByteBuffer value) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The ByteOutput is free to retain a reference to the value beyond the scope of this method call (e.g. write later) since it is considered immutable and is guaranteed not to change by the caller.

      NOTE: This method MUST NOT modify the value. Doing so is a programming error and will lead to data corruption which will be difficult to debug.

      Specified by:
      writeLazy in class ByteOutput
      Parameters:
      value - the bytes to be written. Upon returning from this call, the position of this buffer will be set to the limit
      Throws:
      IOException - thrown if an error occurred while writing
    • computeInt32Size

      public static int computeInt32Size(int fieldNumber, int value)
      Compute the number of bytes that would be needed to encode an int32 field, including tag.
    • computeUInt32Size

      public static int computeUInt32Size(int fieldNumber, int value)
      Compute the number of bytes that would be needed to encode a uint32 field, including tag.
    • computeSInt32Size

      public static int computeSInt32Size(int fieldNumber, int value)
      Compute the number of bytes that would be needed to encode an sint32 field, including tag.
    • computeFixed32Size

      public static int computeFixed32Size(int fieldNumber, int value)
      Compute the number of bytes that would be needed to encode a fixed32 field, including tag.
    • computeSFixed32Size

      public static int computeSFixed32Size(int fieldNumber, int value)
      Compute the number of bytes that would be needed to encode an sfixed32 field, including tag.
    • computeInt64Size

      public static int computeInt64Size(int fieldNumber, long value)
      Compute the number of bytes that would be needed to encode an int64 field, including tag.
    • computeUInt64Size

      public static int computeUInt64Size(int fieldNumber, long value)
      Compute the number of bytes that would be needed to encode a uint64 field, including tag.
    • computeSInt64Size

      public static int computeSInt64Size(int fieldNumber, long value)
      Compute the number of bytes that would be needed to encode an sint64 field, including tag.
    • computeFixed64Size

      public static int computeFixed64Size(int fieldNumber, long value)
      Compute the number of bytes that would be needed to encode a fixed64 field, including tag.
    • computeSFixed64Size

      public static int computeSFixed64Size(int fieldNumber, long value)
      Compute the number of bytes that would be needed to encode an sfixed64 field, including tag.
    • computeFloatSize

      public static int computeFloatSize(int fieldNumber, float value)
      Compute the number of bytes that would be needed to encode a float field, including tag.
    • computeDoubleSize

      public static int computeDoubleSize(int fieldNumber, double value)
      Compute the number of bytes that would be needed to encode a double field, including tag.
    • computeBoolSize

      public static int computeBoolSize(int fieldNumber, boolean value)
      Compute the number of bytes that would be needed to encode a bool field, including tag.
    • computeEnumSize

      public static int computeEnumSize(int fieldNumber, int value)
      Compute the number of bytes that would be needed to encode an enum field, including tag. The provided value is the numeric value used to represent the enum value on the wire (not the enum ordinal value).
    • computeStringSize

      public static int computeStringSize(int fieldNumber, String value)
      Compute the number of bytes that would be needed to encode a string field, including tag.
    • computeBytesSize

      public static int computeBytesSize(int fieldNumber, ByteString value)
      Compute the number of bytes that would be needed to encode a bytes field, including tag.
    • computeByteArraySize

      public static int computeByteArraySize(int fieldNumber, byte[] value)
      Compute the number of bytes that would be needed to encode a bytes field, including tag.
    • computeByteBufferSize

      public static int computeByteBufferSize(int fieldNumber, ByteBuffer value)
      Compute the number of bytes that would be needed to encode a bytes field, including tag.
    • computeLazyFieldSize

      public static int computeLazyFieldSize(int fieldNumber, LazyFieldLite value)
      Compute the number of bytes that would be needed to encode an embedded message in lazy field, including tag.
    • computeMessageSize

      public static int computeMessageSize(int fieldNumber, MessageLite value)
      Compute the number of bytes that would be needed to encode an embedded message field, including tag.
    • computeMessageSize

      static int computeMessageSize(int fieldNumber, MessageLite value, Schema schema)
      Compute the number of bytes that would be needed to encode an embedded message field, including tag.
    • computeMessageSetExtensionSize

      public static int computeMessageSetExtensionSize(int fieldNumber, MessageLite value)
      Compute the number of bytes that would be needed to encode a MessageSet extension to the stream. For historical reasons, the wire format differs from normal fields.
    • computeRawMessageSetExtensionSize

      public static int computeRawMessageSetExtensionSize(int fieldNumber, ByteString value)
      Compute the number of bytes that would be needed to encode an unparsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.
    • computeLazyFieldMessageSetExtensionSize

      public static int computeLazyFieldMessageSetExtensionSize(int fieldNumber, LazyFieldLite value)
      Compute the number of bytes that would be needed to encode a lazily parsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.
    • computeTagSize

      public static int computeTagSize(int fieldNumber)
      Compute the number of bytes that would be needed to encode a tag.
    • computeInt32SizeNoTag

      public static int computeInt32SizeNoTag(int value)
      Compute the number of bytes that would be needed to encode an int32 field, including tag.
    • computeUInt32SizeNoTag

      public static int computeUInt32SizeNoTag(int value)
      Compute the number of bytes that would be needed to encode a uint32 field.
    • computeSInt32SizeNoTag

      public static int computeSInt32SizeNoTag(int value)
      Compute the number of bytes that would be needed to encode an sint32 field.
    • computeFixed32SizeNoTag

      public static int computeFixed32SizeNoTag(int unused)
      Compute the number of bytes that would be needed to encode a fixed32 field.
    • computeSFixed32SizeNoTag

      public static int computeSFixed32SizeNoTag(int unused)
      Compute the number of bytes that would be needed to encode an sfixed32 field.
    • computeInt64SizeNoTag

      public static int computeInt64SizeNoTag(long value)
      Compute the number of bytes that would be needed to encode an int64 field, including tag.
    • computeUInt64SizeNoTag

      public static int computeUInt64SizeNoTag(long value)
      Compute the number of bytes that would be needed to encode a uint64 field, including tag.
    • computeSInt64SizeNoTag

      public static int computeSInt64SizeNoTag(long value)
      Compute the number of bytes that would be needed to encode an sint64 field.
    • computeFixed64SizeNoTag

      public static int computeFixed64SizeNoTag(long unused)
      Compute the number of bytes that would be needed to encode a fixed64 field.
    • computeSFixed64SizeNoTag

      public static int computeSFixed64SizeNoTag(long unused)
      Compute the number of bytes that would be needed to encode an sfixed64 field.
    • computeFloatSizeNoTag

      public static int computeFloatSizeNoTag(float unused)
      Compute the number of bytes that would be needed to encode a float field, including tag.
    • computeDoubleSizeNoTag

      public static int computeDoubleSizeNoTag(double unused)
      Compute the number of bytes that would be needed to encode a double field, including tag.
    • computeBoolSizeNoTag

      public static int computeBoolSizeNoTag(boolean unused)
      Compute the number of bytes that would be needed to encode a bool field.
    • computeEnumSizeNoTag

      public static int computeEnumSizeNoTag(int value)
      Compute the number of bytes that would be needed to encode an enum field. The provided value is the numeric value used to represent the enum value on the wire (not the enum ordinal value).
    • computeStringSizeNoTag

      public static int computeStringSizeNoTag(String value)
      Compute the number of bytes that would be needed to encode a string field.
    • computeLazyFieldSizeNoTag

      public static int computeLazyFieldSizeNoTag(LazyFieldLite value)
      Compute the number of bytes that would be needed to encode an embedded message stored in lazy field.
    • computeBytesSizeNoTag

      public static int computeBytesSizeNoTag(ByteString value)
      Compute the number of bytes that would be needed to encode a bytes field.
    • computeByteArraySizeNoTag

      public static int computeByteArraySizeNoTag(byte[] value)
      Compute the number of bytes that would be needed to encode a bytes field.
    • computeByteBufferSizeNoTag

      public static int computeByteBufferSizeNoTag(ByteBuffer value)
      Compute the number of bytes that would be needed to encode a bytes field.
    • computeMessageSizeNoTag

      public static int computeMessageSizeNoTag(MessageLite value)
      Compute the number of bytes that would be needed to encode an embedded message field.
    • computeMessageSizeNoTag

      static int computeMessageSizeNoTag(MessageLite value, Schema schema)
      Compute the number of bytes that would be needed to encode an embedded message field.
    • computeLengthDelimitedFieldSize

      static int computeLengthDelimitedFieldSize(int fieldLength)
    • encodeZigZag32

      public static int encodeZigZag32(int n)
      Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into values that can be efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, thus always taking 10 bytes on the wire.)
      Parameters:
      n - A signed 32-bit integer.
      Returns:
      An unsigned 32-bit integer, stored in a signed int because Java has no explicit unsigned support.
    • encodeZigZag64

      public static long encodeZigZag64(long n)
      Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into values that can be efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, thus always taking 10 bytes on the wire.)
      Parameters:
      n - A signed 64-bit integer.
      Returns:
      An unsigned 64-bit integer, stored in a signed int because Java has no explicit unsigned support.
    • flush

      public abstract void flush() throws IOException
      Flushes the stream and forces any buffered bytes to be written. This does not flush the underlying OutputStream.
      Throws:
      IOException
    • spaceLeft

      public abstract int spaceLeft()
      If writing to a flat array, return the space left in the array. Otherwise, throws UnsupportedOperationException.
    • checkNoSpaceLeft

      public final void checkNoSpaceLeft()
      Verifies that spaceLeft() returns zero. It's common to create a byte array that is exactly big enough to hold a message, then write to it with a CodedOutputStream. Calling checkNoSpaceLeft() after writing verifies that the message was actually as big as expected, which can help catch bugs.
    • getTotalBytesWritten

      public abstract int getTotalBytesWritten()
      Get the total number of bytes successfully written to this stream. The returned value is not guaranteed to be accurate if exceptions have been found in the middle of writing.
    • writeByteArrayNoTag

      abstract void writeByteArrayNoTag(byte[] value, int offset, int length) throws IOException
      Write a bytes field to the stream. Visible for testing.
      Throws:
      IOException
    • inefficientWriteStringNoTag

      final void inefficientWriteStringNoTag(String value, Utf8.UnpairedSurrogateException cause) throws IOException
      Throws:
      IOException
    • writeGroup

      @Deprecated public final void writeGroup(int fieldNumber, MessageLite value) throws IOException
      Deprecated.
      groups are deprecated.
      Write a group field, including tag, to the stream.
      Throws:
      IOException
    • writeGroup

      @Deprecated final void writeGroup(int fieldNumber, MessageLite value, Schema schema) throws IOException
      Deprecated.
      groups are deprecated.
      Write a group field, including tag, to the stream.
      Throws:
      IOException
    • writeGroupNoTag

      @Deprecated public final void writeGroupNoTag(MessageLite value) throws IOException
      Deprecated.
      groups are deprecated.
      Write a group field to the stream.
      Throws:
      IOException
    • writeGroupNoTag

      @Deprecated final void writeGroupNoTag(MessageLite value, Schema schema) throws IOException
      Deprecated.
      groups are deprecated.
      Write a group field to the stream.
      Throws:
      IOException
    • computeGroupSize

      @Deprecated public static int computeGroupSize(int fieldNumber, MessageLite value)
      Deprecated.
      groups are deprecated.
      Compute the number of bytes that would be needed to encode a group field, including tag.
    • computeGroupSize

      @Deprecated static int computeGroupSize(int fieldNumber, MessageLite value, Schema schema)
      Deprecated.
      groups are deprecated.
      Compute the number of bytes that would be needed to encode a group field, including tag.
    • computeGroupSizeNoTag

      @Deprecated public static int computeGroupSizeNoTag(MessageLite value)
      Deprecated.
      Compute the number of bytes that would be needed to encode a group field.
    • computeGroupSizeNoTag

      @Deprecated static int computeGroupSizeNoTag(MessageLite value, Schema schema)
      Deprecated.
      Compute the number of bytes that would be needed to encode a group field.
    • writeRawVarint32

      @Deprecated public final void writeRawVarint32(int value) throws IOException
      Deprecated.
      Encode and write a varint. value is treated as unsigned, so it won't be sign-extended if negative.
      Throws:
      IOException
    • writeRawVarint64

      @Deprecated public final void writeRawVarint64(long value) throws IOException
      Deprecated.
      Encode and write a varint.
      Throws:
      IOException
    • computeRawVarint32Size

      @Deprecated public static int computeRawVarint32Size(int value)
      Deprecated.
      Compute the number of bytes that would be needed to encode a varint. value is treated as unsigned, so it won't be sign-extended if negative.
    • computeRawVarint64Size

      @Deprecated public static int computeRawVarint64Size(long value)
      Deprecated.
      Compute the number of bytes that would be needed to encode a varint.
    • writeRawLittleEndian32

      @Deprecated public final void writeRawLittleEndian32(int value) throws IOException
      Deprecated.
      Write a little-endian 32-bit integer.
      Throws:
      IOException
    • writeRawLittleEndian64

      @Deprecated public final void writeRawLittleEndian64(long value) throws IOException
      Deprecated.
      Write a little-endian 64-bit integer.
      Throws:
      IOException