Package com.google.protobuf

## Class CodedOutputStream

- java.lang.Object
- - com.google.protobuf.CodedOutputStream

    public final class CodedOutputStream
    extends java.lang.Object

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(com.google.protobuf.ByteString)`). 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.

Author:
  kneton@google.com Kenton Varda

### Nested Class Summary

Nested Classes
`static class` `CodedOutputStream.OutOfSpaceException` If you create a CodedOutputStream around a simple flat array, you must not attempt to write more bytes than the array has space.

### Field Summary

Fields
`static int` `DEFAULT_BUFFER_SIZE` The buffer size used in `newInstance(OutputStream)`.
`static int` `LITTLE_ENDIAN_32_SIZE`
`static int` `LITTLE_ENDIAN_64_SIZE`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
`void` `checkNoSpaceLeft()` Verifies that `spaceLeft()` returns zero.
`static int` `computeBoolSize​(int fieldNumber, boolean value)` Compute the number of bytes that would be needed to encode a `bool` field, including tag.
`static int` `computeBoolSizeNoTag​(boolean value)` Compute the number of bytes that would be needed to encode a `bool` field.
`static int` `computeByteArraySize​(int fieldNumber, byte[] value)` Compute the number of bytes that would be needed to encode a `bytes` field, including tag.
`static int` `computeByteArraySizeNoTag​(byte[] value)` Compute the number of bytes that would be needed to encode a `bytes` field.
`static int` `computeByteBufferSize​(int fieldNumber, java.nio.ByteBuffer value)` Compute the number of bytes that would be needed to encode a `bytes` field, including tag.
`static int` `computeByteBufferSizeNoTag​(java.nio.ByteBuffer value)` Compute the number of bytes that would be needed to encode a `bytes` field.
`static int` `computeBytesSize​(int fieldNumber, ByteString value)` Compute the number of bytes that would be needed to encode a `bytes` field, including tag.
`static int` `computeBytesSizeNoTag​(ByteString value)` Compute the number of bytes that would be needed to encode a `bytes` field.
`static int` `computeDoubleSize​(int fieldNumber, double value)` Compute the number of bytes that would be needed to encode a `double` field, including tag.
`static int` `computeDoubleSizeNoTag​(double value)` Compute the number of bytes that would be needed to encode a `double` field, including tag.
`static int` `computeEnumSize​(int fieldNumber, int value)` Compute the number of bytes that would be needed to encode an enum field, including tag.
`static int` `computeEnumSizeNoTag​(int value)` Compute the number of bytes that would be needed to encode an enum field.
`static int` `computeFixed32Size​(int fieldNumber, int value)` Compute the number of bytes that would be needed to encode a `fixed32` field, including tag.
`static int` `computeFixed32SizeNoTag​(int value)` Compute the number of bytes that would be needed to encode a `fixed32` field.
`static int` `computeFixed64Size​(int fieldNumber, long value)` Compute the number of bytes that would be needed to encode a `fixed64` field, including tag.
`static int` `computeFixed64SizeNoTag​(long value)` Compute the number of bytes that would be needed to encode a `fixed64` field.
`static int` `computeFloatSize​(int fieldNumber, float value)` Compute the number of bytes that would be needed to encode a `float` field, including tag.
`static int` `computeFloatSizeNoTag​(float value)` Compute the number of bytes that would be needed to encode a `float` field, including tag.
`static int` `computeGroupSize​(int fieldNumber, MessageLite value)` Compute the number of bytes that would be needed to encode a `group` field, including tag.
`static int` `computeGroupSizeNoTag​(MessageLite value)` Compute the number of bytes that would be needed to encode a `group` field.
`static int` `computeInt32Size​(int fieldNumber, int value)` Compute the number of bytes that would be needed to encode an `int32` field, including tag.
`static int` `computeInt32SizeNoTag​(int value)` Compute the number of bytes that would be needed to encode an `int32` field, including tag.
`static int` `computeInt64Size​(int fieldNumber, long value)` Compute the number of bytes that would be needed to encode an `int64` field, including tag.
`static int` `computeInt64SizeNoTag​(long value)` Compute the number of bytes that would be needed to encode an `int64` field, including tag.
`static int` `computeLazyFieldMessageSetExtensionSize​(int fieldNumber, LazyFieldLite value)` Compute the number of bytes that would be needed to encode an lazily parsed MessageSet extension field to the stream.
`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.
`static int` `computeLazyFieldSizeNoTag​(LazyFieldLite value)` Compute the number of bytes that would be needed to encode an embedded message stored in lazy field.
`static int` `computeMessageSetExtensionSize​(int fieldNumber, MessageLite value)` Compute the number of bytes that would be needed to encode a MessageSet extension to the stream.
`static int` `computeMessageSize​(int fieldNumber, MessageLite value)` Compute the number of bytes that would be needed to encode an embedded message field, including tag.
`static int` `computeMessageSizeNoTag​(MessageLite value)` Compute the number of bytes that would be needed to encode an embedded message field.
`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.
`static int` `computeRawVarint32Size​(int value)` Compute the number of bytes that would be needed to encode a varint.
`static int` `computeRawVarint64Size​(long value)` Compute the number of bytes that would be needed to encode a varint.
`static int` `computeSFixed32Size​(int fieldNumber, int value)` Compute the number of bytes that would be needed to encode an `sfixed32` field, including tag.
`static int` `computeSFixed32SizeNoTag​(int value)` Compute the number of bytes that would be needed to encode an `sfixed32` field.
`static int` `computeSFixed64Size​(int fieldNumber, long value)` Compute the number of bytes that would be needed to encode an `sfixed64` field, including tag.
`static int` `computeSFixed64SizeNoTag​(long value)` Compute the number of bytes that would be needed to encode an `sfixed64` field.
`static int` `computeSInt32Size​(int fieldNumber, int value)` Compute the number of bytes that would be needed to encode an `sint32` field, including tag.
`static int` `computeSInt32SizeNoTag​(int value)` Compute the number of bytes that would be needed to encode an `sint32` field.
`static int` `computeSInt64Size​(int fieldNumber, long value)` Compute the number of bytes that would be needed to encode an `sint64` field, including tag.
`static int` `computeSInt64SizeNoTag​(long value)` Compute the number of bytes that would be needed to encode an `sint64` field.
`static int` `computeStringSize​(int fieldNumber, java.lang.String value)` Compute the number of bytes that would be needed to encode a `string` field, including tag.
`static int` `computeStringSizeNoTag​(java.lang.String value)` Compute the number of bytes that would be needed to encode a `string` field.
`static int` `computeTagSize​(int fieldNumber)` Compute the number of bytes that would be needed to encode a tag.
`static int` `computeUInt32Size​(int fieldNumber, int value)` Compute the number of bytes that would be needed to encode a `uint32` field, including tag.
`static int` `computeUInt32SizeNoTag​(int value)` Compute the number of bytes that would be needed to encode a `uint32` field.
`static int` `computeUInt64Size​(int fieldNumber, long value)` Compute the number of bytes that would be needed to encode a `uint64` field, including tag.
`static int` `computeUInt64SizeNoTag​(long value)` Compute the number of bytes that would be needed to encode a `uint64` field, including tag.
`static int` `computeUnknownGroupSize​(int fieldNumber, MessageLite value)` Deprecated. UnknownFieldSet now implements MessageLite, so you can just call `computeGroupSize(int, com.google.protobuf.MessageLite)`.
`static int` `computeUnknownGroupSizeNoTag​(MessageLite value)` Deprecated. UnknownFieldSet now implements MessageLite, so you can just call `computeUnknownGroupSizeNoTag(com.google.protobuf.MessageLite)`.
`static int` `encodeZigZag32​(int n)` Encode a ZigZag-encoded 32-bit value.
`static long` `encodeZigZag64​(long n)` Encode a ZigZag-encoded 64-bit value.
`void` `flush()` Flushes the stream and forces any buffered bytes to be written.
`int` `getTotalBytesWritten()` Get the total number of bytes successfully written to this stream.
`static CodedOutputStream` `newInstance​(byte[] flatArray)` Create a new `CodedOutputStream` that writes directly to the given byte array.
`static CodedOutputStream` `newInstance​(byte[] flatArray, int offset, int length)` Create a new `CodedOutputStream` that writes directly to the given byte array slice.
`static CodedOutputStream` `newInstance​(java.io.OutputStream output)` Create a new `CodedOutputStream` wrapping the given `OutputStream`.
`static CodedOutputStream` `newInstance​(java.io.OutputStream output, int bufferSize)` Create a new `CodedOutputStream` wrapping the given `OutputStream` with a given buffer size.
`static CodedOutputStream` `newInstance​(java.nio.ByteBuffer byteBuffer)` Create a new `CodedOutputStream` that writes to the given ByteBuffer.
`static CodedOutputStream` `newInstance​(java.nio.ByteBuffer byteBuffer, int bufferSize)` Create a new `CodedOutputStream` that writes to the given ByteBuffer.
`int` `spaceLeft()` If writing to a flat array, return the space left in the array.
`void` `writeBool​(int fieldNumber, boolean value)` Write a `bool` field, including tag, to the stream.
`void` `writeBoolNoTag​(boolean value)` Write a `bool` field to the stream.
`void` `writeByteArray​(int fieldNumber, byte[] value)` Write a `bytes` field, including tag, to the stream.
`void` `writeByteArray​(int fieldNumber, byte[] value, int offset, int length)` Write a `bytes` field, including tag, to the stream.
`void` `writeByteArrayNoTag​(byte[] value)` Write a `bytes` field to the stream.
`void` `writeByteArrayNoTag​(byte[] value, int offset, int length)` Write a `bytes` field to the stream.
`void` `writeByteBuffer​(int fieldNumber, java.nio.ByteBuffer value)` Write a `bytes` field, including tag, to the stream.
`void` `writeByteBufferNoTag​(java.nio.ByteBuffer value)` Write a `bytes` field to the stream.
`void` `writeBytes​(int fieldNumber, ByteString value)` Write a `bytes` field, including tag, to the stream.
`void` `writeBytesNoTag​(ByteString value)` Write a `bytes` field to the stream.
`void` `writeDouble​(int fieldNumber, double value)` Write a `double` field, including tag, to the stream.
`void` `writeDoubleNoTag​(double value)` Write a `double` field to the stream.
`void` `writeEnum​(int fieldNumber, int value)` Write an enum field, including tag, to the stream.
`void` `writeEnumNoTag​(int value)` Write an enum field to the stream.
`void` `writeFixed32​(int fieldNumber, int value)` Write a `fixed32` field, including tag, to the stream.
`void` `writeFixed32NoTag​(int value)` Write a `fixed32` field to the stream.
`void` `writeFixed64​(int fieldNumber, long value)` Write a `fixed64` field, including tag, to the stream.
`void` `writeFixed64NoTag​(long value)` Write a `fixed64` field to the stream.
`void` `writeFloat​(int fieldNumber, float value)` Write a `float` field, including tag, to the stream.
`void` `writeFloatNoTag​(float value)` Write a `float` field to the stream.
`void` `writeGroup​(int fieldNumber, MessageLite value)` Write a `group` field, including tag, to the stream.
`void` `writeGroupNoTag​(MessageLite value)` Write a `group` field to the stream.
`void` `writeInt32​(int fieldNumber, int value)` Write an `int32` field, including tag, to the stream.
`void` `writeInt32NoTag​(int value)` Write an `int32` field to the stream.
`void` `writeInt64​(int fieldNumber, long value)` Write an `int64` field, including tag, to the stream.
`void` `writeInt64NoTag​(long value)` Write an `int64` field to the stream.
`void` `writeMessage​(int fieldNumber, MessageLite value)` Write an embedded message field, including tag, to the stream.
`void` `writeMessageNoTag​(MessageLite value)` Write an embedded message field to the stream.
`void` `writeMessageSetExtension​(int fieldNumber, MessageLite value)` Write a MessageSet extension field to the stream.
`void` `writeRawByte​(byte value)` Write a single byte.
`void` `writeRawByte​(int value)` Write a single byte, represented by an integer value.
`void` `writeRawBytes​(byte[] value)` Write an array of bytes.
`void` `writeRawBytes​(byte[] value, int offset, int length)` Write part of an array of bytes.
`void` `writeRawBytes​(ByteString value)` Write a byte string.
`void` `writeRawBytes​(ByteString value, int offset, int length)` Write part of a byte string.
`void` `writeRawBytes​(java.nio.ByteBuffer value)` Write a ByteBuffer.
`void` `writeRawLittleEndian32​(int value)` Write a little-endian 32-bit integer.
`void` `writeRawLittleEndian64​(long value)` Write a little-endian 64-bit integer.
`void` `writeRawMessageSetExtension​(int fieldNumber, ByteString value)` Write an unparsed MessageSet extension field to the stream.
`void` `writeRawVarint32​(int value)` Encode and write a varint.
`void` `writeRawVarint64​(long value)` Encode and write a varint.
`void` `writeSFixed32​(int fieldNumber, int value)` Write an `sfixed32` field, including tag, to the stream.
`void` `writeSFixed32NoTag​(int value)` Write an `sfixed32` field to the stream.
`void` `writeSFixed64​(int fieldNumber, long value)` Write an `sfixed64` field, including tag, to the stream.
`void` `writeSFixed64NoTag​(long value)` Write an `sfixed64` field to the stream.
`void` `writeSInt32​(int fieldNumber, int value)` Write an `sint32` field, including tag, to the stream.
`void` `writeSInt32NoTag​(int value)` Write an `sint32` field to the stream.
`void` `writeSInt64​(int fieldNumber, long value)` Write an `sint64` field, including tag, to the stream.
`void` `writeSInt64NoTag​(long value)` Write an `sint64` field to the stream.
`void` `writeString​(int fieldNumber, java.lang.String value)` Write a `string` field, including tag, to the stream.
`void` `writeStringNoTag​(java.lang.String value)` Write a `string` field to the stream.
`void` `writeTag​(int fieldNumber, int wireType)` Encode and write a tag.
`void` `writeUInt32​(int fieldNumber, int value)` Write a `uint32` field, including tag, to the stream.
`void` `writeUInt32NoTag​(int value)` Write a `uint32` field to the stream.
`void` `writeUInt64​(int fieldNumber, long value)` Write a `uint64` field, including tag, to the stream.
`void` `writeUInt64NoTag​(long value)` Write a `uint64` field to the stream.
`void` `writeUnknownGroup​(int fieldNumber, MessageLite value)` Deprecated. UnknownFieldSet now implements MessageLite, so you can just call `writeGroup(int, com.google.protobuf.MessageLite)`.
`void` `writeUnknownGroupNoTag​(MessageLite value)` Deprecated. UnknownFieldSet now implements MessageLite, so you can just call `writeGroupNoTag(com.google.protobuf.MessageLite)`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DEFAULT_BUFFER_SIZE

    public static final int DEFAULT_BUFFER_SIZE

The buffer size used in `newInstance(OutputStream)`.

See Also:
  Constant Field Values

#### LITTLE_ENDIAN_32_SIZE

    public static final int LITTLE_ENDIAN_32_SIZE

See Also:
  Constant Field Values

#### LITTLE_ENDIAN_64_SIZE

    public static final int LITTLE_ENDIAN_64_SIZE

See Also:
  Constant Field Values

### Method Detail

#### newInstance

    public static CodedOutputStream newInstance​(java.io.OutputStream output)

Create a new `CodedOutputStream` wrapping the given `OutputStream`.

#### newInstance

    public static CodedOutputStream newInstance​(java.io.OutputStream output,
                                                int bufferSize)

Create a new `CodedOutputStream` wrapping the given `OutputStream` with a given buffer size.

#### 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​(java.nio.ByteBuffer byteBuffer)

Create a new `CodedOutputStream` that writes to the given ByteBuffer.

#### newInstance

    public static CodedOutputStream newInstance​(java.nio.ByteBuffer byteBuffer,
                                                int bufferSize)

Create a new `CodedOutputStream` that writes to the given ByteBuffer.

#### writeDouble

    public void writeDouble​(int fieldNumber,
                            double value)
                     throws java.io.IOException

Write a `double` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeFloat

    public void writeFloat​(int fieldNumber,
                           float value)
                    throws java.io.IOException

Write a `float` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeUInt64

    public void writeUInt64​(int fieldNumber,
                            long value)
                     throws java.io.IOException

Write a `uint64` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeInt64

    public void writeInt64​(int fieldNumber,
                           long value)
                    throws java.io.IOException

Write an `int64` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeInt32

    public void writeInt32​(int fieldNumber,
                           int value)
                    throws java.io.IOException

Write an `int32` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeFixed64

    public void writeFixed64​(int fieldNumber,
                             long value)
                      throws java.io.IOException

Write a `fixed64` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeFixed32

    public void writeFixed32​(int fieldNumber,
                             int value)
                      throws java.io.IOException

Write a `fixed32` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeBool

    public void writeBool​(int fieldNumber,
                          boolean value)
                   throws java.io.IOException

Write a `bool` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeString

    public void writeString​(int fieldNumber,
                            java.lang.String value)
                     throws java.io.IOException

Write a `string` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeGroup

    public void writeGroup​(int fieldNumber,
                           MessageLite value)
                    throws java.io.IOException

Write a `group` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeUnknownGroup

    @Deprecated
    public void writeUnknownGroup​(int fieldNumber,
                                  MessageLite value)
                           throws java.io.IOException

Deprecated.
UnknownFieldSet now implements MessageLite, so you can just call `writeGroup(int, com.google.protobuf.MessageLite)`.
Write a group represented by an `UnknownFieldSet`.

Throws:
  `java.io.IOException`

#### writeMessage

    public void writeMessage​(int fieldNumber,
                             MessageLite value)
                      throws java.io.IOException

Write an embedded message field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeBytes

    public void writeBytes​(int fieldNumber,
                           ByteString value)
                    throws java.io.IOException

Write a `bytes` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeByteArray

    public void writeByteArray​(int fieldNumber,
                               byte[] value)
                        throws java.io.IOException

Write a `bytes` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeByteArray

    public void writeByteArray​(int fieldNumber,
                               byte[] value,
                               int offset,
                               int length)
                        throws java.io.IOException

Write a `bytes` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeByteBuffer

    public void writeByteBuffer​(int fieldNumber,
                                java.nio.ByteBuffer value)
                         throws java.io.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:
  `java.io.IOException`

#### writeUInt32

    public void writeUInt32​(int fieldNumber,
                            int value)
                     throws java.io.IOException

Write a `uint32` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeEnum

    public void writeEnum​(int fieldNumber,
                          int value)
                   throws java.io.IOException

Write an enum field, including tag, to the stream. Caller is responsible for converting the enum value to its numeric value.

Throws:
  `java.io.IOException`

#### writeSFixed32

    public void writeSFixed32​(int fieldNumber,
                              int value)
                       throws java.io.IOException

Write an `sfixed32` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeSFixed64

    public void writeSFixed64​(int fieldNumber,
                              long value)
                       throws java.io.IOException

Write an `sfixed64` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeSInt32

    public void writeSInt32​(int fieldNumber,
                            int value)
                     throws java.io.IOException

Write an `sint32` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeSInt64

    public void writeSInt64​(int fieldNumber,
                            long value)
                     throws java.io.IOException

Write an `sint64` field, including tag, to the stream.

Throws:
  `java.io.IOException`

#### writeMessageSetExtension

    public void writeMessageSetExtension​(int fieldNumber,
                                         MessageLite value)
                                  throws java.io.IOException

Write a MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.

Throws:
  `java.io.IOException`

#### writeRawMessageSetExtension

    public void writeRawMessageSetExtension​(int fieldNumber,
                                            ByteString value)
                                     throws java.io.IOException

Write an unparsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.

Throws:
  `java.io.IOException`

#### writeDoubleNoTag

    public void writeDoubleNoTag​(double value)
                          throws java.io.IOException

Write a `double` field to the stream.

Throws:
  `java.io.IOException`

#### writeFloatNoTag

    public void writeFloatNoTag​(float value)
                         throws java.io.IOException

Write a `float` field to the stream.

Throws:
  `java.io.IOException`

#### writeUInt64NoTag

    public void writeUInt64NoTag​(long value)
                          throws java.io.IOException

Write a `uint64` field to the stream.

Throws:
  `java.io.IOException`

#### writeInt64NoTag

    public void writeInt64NoTag​(long value)
                         throws java.io.IOException

Write an `int64` field to the stream.

Throws:
  `java.io.IOException`

#### writeInt32NoTag

    public void writeInt32NoTag​(int value)
                         throws java.io.IOException

Write an `int32` field to the stream.

Throws:
  `java.io.IOException`

#### writeFixed64NoTag

    public void writeFixed64NoTag​(long value)
                           throws java.io.IOException

Write a `fixed64` field to the stream.

Throws:
  `java.io.IOException`

#### writeFixed32NoTag

    public void writeFixed32NoTag​(int value)
                           throws java.io.IOException

Write a `fixed32` field to the stream.

Throws:
  `java.io.IOException`

#### writeBoolNoTag

    public void writeBoolNoTag​(boolean value)
                        throws java.io.IOException

Write a `bool` field to the stream.

Throws:
  `java.io.IOException`

#### writeStringNoTag

    public void writeStringNoTag​(java.lang.String value)
                          throws java.io.IOException

Write a `string` field to the stream.

Throws:
  `java.io.IOException`

#### writeGroupNoTag

    public void writeGroupNoTag​(MessageLite value)
                         throws java.io.IOException

Write a `group` field to the stream.

Throws:
  `java.io.IOException`

#### writeUnknownGroupNoTag

    @Deprecated
    public void writeUnknownGroupNoTag​(MessageLite value)
                                throws java.io.IOException

Deprecated.
UnknownFieldSet now implements MessageLite, so you can just call `writeGroupNoTag(com.google.protobuf.MessageLite)`.
Write a group represented by an `UnknownFieldSet`.

Throws:
  `java.io.IOException`

#### writeMessageNoTag

    public void writeMessageNoTag​(MessageLite value)
                           throws java.io.IOException

Write an embedded message field to the stream.

Throws:
  `java.io.IOException`

#### writeBytesNoTag

    public void writeBytesNoTag​(ByteString value)
                         throws java.io.IOException

Write a `bytes` field to the stream.

Throws:
  `java.io.IOException`

#### writeByteArrayNoTag

    public void writeByteArrayNoTag​(byte[] value)
                             throws java.io.IOException

Write a `bytes` field to the stream.

Throws:
  `java.io.IOException`

#### writeByteArrayNoTag

    public void writeByteArrayNoTag​(byte[] value,
                                    int offset,
                                    int length)
                             throws java.io.IOException

Write a `bytes` field to the stream.

Throws:
  `java.io.IOException`

#### writeByteBufferNoTag

    public void writeByteBufferNoTag​(java.nio.ByteBuffer value)
                              throws java.io.IOException

Write a `bytes` field 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 `writeByteBufferNoTag(byteBuffer.slice())`.

Throws:
  `java.io.IOException`

#### writeUInt32NoTag

    public void writeUInt32NoTag​(int value)
                          throws java.io.IOException

Write a `uint32` field to the stream.

Throws:
  `java.io.IOException`

#### writeEnumNoTag

    public void writeEnumNoTag​(int value)
                        throws java.io.IOException

Write an enum field to the stream. Caller is responsible for converting the enum value to its numeric value.

Throws:
  `java.io.IOException`

#### writeSFixed32NoTag

    public void writeSFixed32NoTag​(int value)
                            throws java.io.IOException

Write an `sfixed32` field to the stream.

Throws:
  `java.io.IOException`

#### writeSFixed64NoTag

    public void writeSFixed64NoTag​(long value)
                            throws java.io.IOException

Write an `sfixed64` field to the stream.

Throws:
  `java.io.IOException`

#### writeSInt32NoTag

    public void writeSInt32NoTag​(int value)
                          throws java.io.IOException

Write an `sint32` field to the stream.

Throws:
  `java.io.IOException`

#### writeSInt64NoTag

    public void writeSInt64NoTag​(long value)
                          throws java.io.IOException

Write an `sint64` field to the stream.

Throws:
  `java.io.IOException`

#### 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.

#### 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.

#### 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.

#### 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.

#### 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.

#### 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.

#### 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.

#### 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.

#### computeStringSize

    public static int computeStringSize​(int fieldNumber,
                                        java.lang.String value)

Compute the number of bytes that would be needed to encode a `string` field, including tag.

#### computeGroupSize

    public static int computeGroupSize​(int fieldNumber,
                                       MessageLite value)

Compute the number of bytes that would be needed to encode a `group` field, including tag.

#### computeUnknownGroupSize

    @Deprecated
    public static int computeUnknownGroupSize​(int fieldNumber,
                                              MessageLite value)

Deprecated.
UnknownFieldSet now implements MessageLite, so you can just call `computeGroupSize(int, com.google.protobuf.MessageLite)`.
Compute the number of bytes that would be needed to encode a `group` field represented by an `UnknownFieldSet`, 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.

#### 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,
                                            java.nio.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.

#### 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.

#### 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. Caller is responsible for converting the enum value to its numeric value.

#### 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.

#### 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.

#### 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.

#### 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.

#### 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 an lazily parsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.

#### computeDoubleSizeNoTag

    public static int computeDoubleSizeNoTag​(double value)

Compute the number of bytes that would be needed to encode a `double` field, including tag.

#### computeFloatSizeNoTag

    public static int computeFloatSizeNoTag​(float value)

Compute the number of bytes that would be needed to encode a `float` 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.

#### computeInt64SizeNoTag

    public static int computeInt64SizeNoTag​(long value)

Compute the number of bytes that would be needed to encode an `int64` field, including tag.

#### computeInt32SizeNoTag

    public static int computeInt32SizeNoTag​(int value)

Compute the number of bytes that would be needed to encode an `int32` field, including tag.

#### computeFixed64SizeNoTag

    public static int computeFixed64SizeNoTag​(long value)

Compute the number of bytes that would be needed to encode a `fixed64` field.

#### computeFixed32SizeNoTag

    public static int computeFixed32SizeNoTag​(int value)

Compute the number of bytes that would be needed to encode a `fixed32` field.

#### computeBoolSizeNoTag

    public static int computeBoolSizeNoTag​(boolean value)

Compute the number of bytes that would be needed to encode a `bool` field.

#### computeStringSizeNoTag

    public static int computeStringSizeNoTag​(java.lang.String value)

Compute the number of bytes that would be needed to encode a `string` field.

#### computeGroupSizeNoTag

    public static int computeGroupSizeNoTag​(MessageLite value)

Compute the number of bytes that would be needed to encode a `group` field.

#### computeUnknownGroupSizeNoTag

    @Deprecated
    public static int computeUnknownGroupSizeNoTag​(MessageLite value)

Deprecated.
UnknownFieldSet now implements MessageLite, so you can just call `computeUnknownGroupSizeNoTag(com.google.protobuf.MessageLite)`.
Compute the number of bytes that would be needed to encode a `group` field represented by an `UnknownFieldSet`, including tag.

#### computeMessageSizeNoTag

    public static int computeMessageSizeNoTag​(MessageLite value)

Compute the number of bytes that would be needed to encode an embedded message 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​(java.nio.ByteBuffer value)

Compute the number of bytes that would be needed to encode a `bytes` field.

#### computeUInt32SizeNoTag

    public static int computeUInt32SizeNoTag​(int value)

Compute the number of bytes that would be needed to encode a `uint32` field.

#### computeEnumSizeNoTag

    public static int computeEnumSizeNoTag​(int value)

Compute the number of bytes that would be needed to encode an enum field. Caller is responsible for converting the enum value to its numeric value.

#### computeSFixed32SizeNoTag

    public static int computeSFixed32SizeNoTag​(int value)

Compute the number of bytes that would be needed to encode an `sfixed32` field.

#### computeSFixed64SizeNoTag

    public static int computeSFixed64SizeNoTag​(long value)

Compute the number of bytes that would be needed to encode an `sfixed64` field.

#### computeSInt32SizeNoTag

    public static int computeSInt32SizeNoTag​(int value)

Compute the number of bytes that would be needed to encode an `sint32` field.

#### computeSInt64SizeNoTag

    public static int computeSInt64SizeNoTag​(long value)

Compute the number of bytes that would be needed to encode an `sint64` field.

#### flush

    public void flush()
               throws java.io.IOException

Flushes the stream and forces any buffered bytes to be written. This does not flush the underlying OutputStream.

Throws:
  `java.io.IOException`

#### spaceLeft

    public int spaceLeft()

If writing to a flat array, return the space left in the array. Otherwise, throws `UnsupportedOperationException`.

#### checkNoSpaceLeft

    public 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 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.

#### writeRawByte

    public void writeRawByte​(byte value)
                      throws java.io.IOException

Write a single byte.

Throws:
  `java.io.IOException`

#### writeRawByte

    public void writeRawByte​(int value)
                      throws java.io.IOException

Write a single byte, represented by an integer value.

Throws:
  `java.io.IOException`

#### writeRawBytes

    public void writeRawBytes​(ByteString value)
                       throws java.io.IOException

Write a byte string.

Throws:
  `java.io.IOException`

#### writeRawBytes

    public void writeRawBytes​(byte[] value)
                       throws java.io.IOException

Write an array of bytes.

Throws:
  `java.io.IOException`

#### writeRawBytes

    public void writeRawBytes​(java.nio.ByteBuffer value)
                       throws java.io.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:
  `java.io.IOException`

#### writeRawBytes

    public void writeRawBytes​(byte[] value,
                              int offset,
                              int length)
                       throws java.io.IOException

Write part of an array of bytes.

Throws:
  `java.io.IOException`

#### writeRawBytes

    public void writeRawBytes​(ByteString value,
                              int offset,
                              int length)
                       throws java.io.IOException

Write part of a byte string.

Throws:
  `java.io.IOException`

#### writeTag

    public void writeTag​(int fieldNumber,
                         int wireType)
                  throws java.io.IOException

Encode and write a tag.

Throws:
  `java.io.IOException`

#### computeTagSize

    public static int computeTagSize​(int fieldNumber)

Compute the number of bytes that would be needed to encode a tag.

#### writeRawVarint32

    public void writeRawVarint32​(int value)
                          throws java.io.IOException

Encode and write a varint. `value` is treated as unsigned, so it won't be sign-extended if negative.

Throws:
  `java.io.IOException`

#### computeRawVarint32Size

    public static int computeRawVarint32Size​(int value)

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.

#### writeRawVarint64

    public void writeRawVarint64​(long value)
                          throws java.io.IOException

Encode and write a varint.

Throws:
  `java.io.IOException`

#### computeRawVarint64Size

    public static int computeRawVarint64Size​(long value)

Compute the number of bytes that would be needed to encode a varint.

#### writeRawLittleEndian32

    public void writeRawLittleEndian32​(int value)
                                throws java.io.IOException

Write a little-endian 32-bit integer.

Throws:
  `java.io.IOException`

#### writeRawLittleEndian64

    public void writeRawLittleEndian64​(long value)
                                throws java.io.IOException

Write a little-endian 64-bit integer.

Throws:
  `java.io.IOException`

#### 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.