Class CodedOutputStream
- java.lang.Object
-
- com.google.protobuf.ByteOutput
-
- com.google.protobuf.CodedOutputStream
-
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)andwriteInt32(int, int)) and methods that write low-level values (e.g.writeRawVarint32(int)andwriteRawBytes(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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCodedOutputStream.OutOfSpaceExceptionIf 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 Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEThe buffer size used innewInstance(OutputStream).static intLITTLE_ENDIAN_32_SIZEDeprecated.UsecomputeFixed32SizeNoTag(int)instead.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcheckNoSpaceLeft()Verifies thatspaceLeft()returns zero.static intcomputeBoolSize(int fieldNumber, boolean value)Compute the number of bytes that would be needed to encode aboolfield, including tag.static intcomputeBoolSizeNoTag(boolean unused)Compute the number of bytes that would be needed to encode aboolfield.static intcomputeByteArraySize(int fieldNumber, byte[] value)Compute the number of bytes that would be needed to encode abytesfield, including tag.static intcomputeByteArraySizeNoTag(byte[] value)Compute the number of bytes that would be needed to encode abytesfield.static intcomputeByteBufferSize(int fieldNumber, java.nio.ByteBuffer value)Compute the number of bytes that would be needed to encode abytesfield, including tag.static intcomputeByteBufferSizeNoTag(java.nio.ByteBuffer value)Compute the number of bytes that would be needed to encode abytesfield.static intcomputeBytesSize(int fieldNumber, ByteString value)Compute the number of bytes that would be needed to encode abytesfield, including tag.static intcomputeBytesSizeNoTag(ByteString value)Compute the number of bytes that would be needed to encode abytesfield.static intcomputeDoubleSize(int fieldNumber, double value)Compute the number of bytes that would be needed to encode adoublefield, including tag.static intcomputeDoubleSizeNoTag(double unused)Compute the number of bytes that would be needed to encode adoublefield, including tag.static intcomputeEnumSize(int fieldNumber, int value)Compute the number of bytes that would be needed to encode an enum field, including tag.static intcomputeEnumSizeNoTag(int value)Compute the number of bytes that would be needed to encode an enum field.static intcomputeFixed32Size(int fieldNumber, int value)Compute the number of bytes that would be needed to encode afixed32field, including tag.static intcomputeFixed32SizeNoTag(int unused)Compute the number of bytes that would be needed to encode afixed32field.static intcomputeFixed64Size(int fieldNumber, long value)Compute the number of bytes that would be needed to encode afixed64field, including tag.static intcomputeFixed64SizeNoTag(long unused)Compute the number of bytes that would be needed to encode afixed64field.static intcomputeFloatSize(int fieldNumber, float value)Compute the number of bytes that would be needed to encode afloatfield, including tag.static intcomputeFloatSizeNoTag(float unused)Compute the number of bytes that would be needed to encode afloatfield, including tag.static intcomputeGroupSize(int fieldNumber, MessageLite value)Deprecated.groups are deprecated.static intcomputeGroupSizeNoTag(MessageLite value)Deprecated.static intcomputeInt32Size(int fieldNumber, int value)Compute the number of bytes that would be needed to encode anint32field, including tag.static intcomputeInt32SizeNoTag(int value)Compute the number of bytes that would be needed to encode anint32field, including tag.static intcomputeInt64Size(int fieldNumber, long value)Compute the number of bytes that would be needed to encode anint64field, including tag.static intcomputeInt64SizeNoTag(long value)Compute the number of bytes that would be needed to encode anint64field, including tag.static intcomputeLazyFieldMessageSetExtensionSize(int fieldNumber, LazyFieldLite value)Compute the number of bytes that would be needed to encode a lazily parsed MessageSet extension field to the stream.static intcomputeLazyFieldSize(int fieldNumber, LazyFieldLite value)Compute the number of bytes that would be needed to encode an embedded message in lazy field, including tag.static intcomputeLazyFieldSizeNoTag(LazyFieldLite value)Compute the number of bytes that would be needed to encode an embedded message stored in lazy field.static intcomputeMessageSetExtensionSize(int fieldNumber, MessageLite value)Compute the number of bytes that would be needed to encode a MessageSet extension to the stream.static intcomputeMessageSize(int fieldNumber, MessageLite value)Compute the number of bytes that would be needed to encode an embedded message field, including tag.static intcomputeMessageSizeNoTag(MessageLite value)Compute the number of bytes that would be needed to encode an embedded message field.static intcomputeRawMessageSetExtensionSize(int fieldNumber, ByteString value)Compute the number of bytes that would be needed to encode an unparsed MessageSet extension field to the stream.static intcomputeRawVarint32Size(int value)Deprecated.usecomputeUInt32SizeNoTag(int)instead.static intcomputeRawVarint64Size(long value)Deprecated.usecomputeUInt64SizeNoTag(long)instead.static intcomputeSFixed32Size(int fieldNumber, int value)Compute the number of bytes that would be needed to encode ansfixed32field, including tag.static intcomputeSFixed32SizeNoTag(int unused)Compute the number of bytes that would be needed to encode ansfixed32field.static intcomputeSFixed64Size(int fieldNumber, long value)Compute the number of bytes that would be needed to encode ansfixed64field, including tag.static intcomputeSFixed64SizeNoTag(long unused)Compute the number of bytes that would be needed to encode ansfixed64field.static intcomputeSInt32Size(int fieldNumber, int value)Compute the number of bytes that would be needed to encode ansint32field, including tag.static intcomputeSInt32SizeNoTag(int value)Compute the number of bytes that would be needed to encode ansint32field.static intcomputeSInt64Size(int fieldNumber, long value)Compute the number of bytes that would be needed to encode ansint64field, including tag.static intcomputeSInt64SizeNoTag(long value)Compute the number of bytes that would be needed to encode ansint64field.static intcomputeStringSize(int fieldNumber, java.lang.String value)Compute the number of bytes that would be needed to encode astringfield, including tag.static intcomputeStringSizeNoTag(java.lang.String value)Compute the number of bytes that would be needed to encode astringfield.static intcomputeTagSize(int fieldNumber)Compute the number of bytes that would be needed to encode a tag.static intcomputeUInt32Size(int fieldNumber, int value)Compute the number of bytes that would be needed to encode auint32field, including tag.static intcomputeUInt32SizeNoTag(int value)Compute the number of bytes that would be needed to encode auint32field.static intcomputeUInt64Size(int fieldNumber, long value)Compute the number of bytes that would be needed to encode auint64field, including tag.static intcomputeUInt64SizeNoTag(long value)Compute the number of bytes that would be needed to encode auint64field, including tag.static intencodeZigZag32(int n)Encode a ZigZag-encoded 32-bit value.static longencodeZigZag64(long n)Encode a ZigZag-encoded 64-bit value.abstract voidflush()Flushes the stream and forces any buffered bytes to be written.abstract intgetTotalBytesWritten()Get the total number of bytes successfully written to this stream.static CodedOutputStreamnewInstance(byte[] flatArray)Create a newCodedOutputStreamthat writes directly to the given byte array.static CodedOutputStreamnewInstance(byte[] flatArray, int offset, int length)Create a newCodedOutputStreamthat writes directly to the given byte array slice.static CodedOutputStreamnewInstance(java.io.OutputStream output)Create a newCodedOutputStreamwrapping the givenOutputStream.static CodedOutputStreamnewInstance(java.io.OutputStream output, int bufferSize)Create a newCodedOutputStreamwrapping the givenOutputStreamwith a given buffer size.static CodedOutputStreamnewInstance(java.nio.ByteBuffer buffer)Create a newCodedOutputStreamthat writes to the givenByteBuffer.static CodedOutputStreamnewInstance(java.nio.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 aByteBuffer.abstract intspaceLeft()If writing to a flat array, return the space left in the array.voiduseDeterministicSerialization()Configures serialization to be deterministic.abstract voidwrite(byte value)Writes a single byte.abstract voidwrite(byte[] value, int offset, int length)Writes a sequence of bytes.abstract voidwrite(java.nio.ByteBuffer value)Writes a sequence of bytes.abstract voidwriteBool(int fieldNumber, boolean value)Write aboolfield, including tag, to the stream.voidwriteBoolNoTag(boolean value)Write aboolfield to the stream.abstract voidwriteByteArray(int fieldNumber, byte[] value)Write abytesfield, including tag, to the stream.abstract voidwriteByteArray(int fieldNumber, byte[] value, int offset, int length)Write abytesfield, including tag, to the stream.voidwriteByteArrayNoTag(byte[] value)Write abytesfield to the stream.abstract voidwriteByteBuffer(int fieldNumber, java.nio.ByteBuffer value)Write abytesfield, including tag, to the stream.abstract voidwriteBytes(int fieldNumber, ByteString value)Write abytesfield, including tag, to the stream.abstract voidwriteBytesNoTag(ByteString value)Write abytesfield to the stream.voidwriteDouble(int fieldNumber, double value)Write adoublefield, including tag, to the stream.voidwriteDoubleNoTag(double value)Write adoublefield to the stream.voidwriteEnum(int fieldNumber, int value)Write an enum field, including tag, to the stream.voidwriteEnumNoTag(int value)Write an enum field to the stream.abstract voidwriteFixed32(int fieldNumber, int value)Write afixed32field, including tag, to the stream.abstract voidwriteFixed32NoTag(int value)Write afixed32field to the stream.abstract voidwriteFixed64(int fieldNumber, long value)Write afixed64field, including tag, to the stream.abstract voidwriteFixed64NoTag(long value)Write afixed64field to the stream.voidwriteFloat(int fieldNumber, float value)Write afloatfield, including tag, to the stream.voidwriteFloatNoTag(float value)Write afloatfield to the stream.voidwriteGroup(int fieldNumber, MessageLite value)Deprecated.groups are deprecated.voidwriteGroupNoTag(MessageLite value)Deprecated.groups are deprecated.abstract voidwriteInt32(int fieldNumber, int value)Write anint32field, including tag, to the stream.abstract voidwriteInt32NoTag(int value)Write anint32field to the stream.voidwriteInt64(int fieldNumber, long value)Write anint64field, including tag, to the stream.voidwriteInt64NoTag(long value)Write anint64field to the stream.abstract voidwriteLazy(byte[] value, int offset, int length)Writes a sequence of bytes.abstract voidwriteLazy(java.nio.ByteBuffer value)Writes a sequence of bytes.abstract voidwriteMessage(int fieldNumber, MessageLite value)Write an embedded message field, including tag, to the stream.abstract voidwriteMessageNoTag(MessageLite value)Write an embedded message field to the stream.abstract voidwriteMessageSetExtension(int fieldNumber, MessageLite value)Write a MessageSet extension field to the stream.voidwriteRawByte(byte value)Write a single byte.voidwriteRawByte(int value)Write a single byte, represented by an integer value.voidwriteRawBytes(byte[] value)Write an array of bytes.voidwriteRawBytes(byte[] value, int offset, int length)Write part of an array of bytes.voidwriteRawBytes(ByteString value)Write a byte string.abstract voidwriteRawBytes(java.nio.ByteBuffer value)Write a ByteBuffer.voidwriteRawLittleEndian32(int value)Deprecated.UsewriteFixed32NoTag(int)instead.voidwriteRawLittleEndian64(long value)Deprecated.UsewriteFixed64NoTag(long)instead.abstract voidwriteRawMessageSetExtension(int fieldNumber, ByteString value)Write an unparsed MessageSet extension field to the stream.voidwriteRawVarint32(int value)Deprecated.usewriteUInt32NoTag(int)instead.voidwriteRawVarint64(long value)Deprecated.usewriteUInt64NoTag(long)instead.voidwriteSFixed32(int fieldNumber, int value)Write ansfixed32field, including tag, to the stream.voidwriteSFixed32NoTag(int value)Write asfixed32field to the stream.voidwriteSFixed64(int fieldNumber, long value)Write ansfixed64field, including tag, to the stream.voidwriteSFixed64NoTag(long value)Write asfixed64field to the stream.voidwriteSInt32(int fieldNumber, int value)Write asint32field, including tag, to the stream.voidwriteSInt32NoTag(int value)Write asint32field to the stream.voidwriteSInt64(int fieldNumber, long value)Write ansint64field, including tag, to the stream.voidwriteSInt64NoTag(long value)Write asint64field to the stream.abstract voidwriteString(int fieldNumber, java.lang.String value)Write astringfield, including tag, to the stream.abstract voidwriteStringNoTag(java.lang.String value)Write astringfield to the stream.abstract voidwriteTag(int fieldNumber, int wireType)Encode and write a tag.abstract voidwriteUInt32(int fieldNumber, int value)Write auint32field, including tag, to the stream.abstract voidwriteUInt32NoTag(int value)Write auint32field to the stream.abstract voidwriteUInt64(int fieldNumber, long value)Write auint64field, including tag, to the stream.abstract voidwriteUInt64NoTag(long value)Write auint64field to the stream.
-
-
-
Field Detail
-
LITTLE_ENDIAN_32_SIZE
@Deprecated public static final int LITTLE_ENDIAN_32_SIZE
Deprecated.UsecomputeFixed32SizeNoTag(int)instead.- See Also:
- Constant Field Values
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
The buffer size used innewInstance(OutputStream).- See Also:
- Constant Field Values
-
-
Method Detail
-
newInstance
public static CodedOutputStream newInstance(java.io.OutputStream output)
Create a newCodedOutputStreamwrapping the givenOutputStream.NOTE: The provided
OutputStreamMUST 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(java.io.OutputStream output, int bufferSize)
Create a newCodedOutputStreamwrapping the givenOutputStreamwith a given buffer size.NOTE: The provided
OutputStreamMUST 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 newCodedOutputStreamthat writes directly to the given byte array. If more bytes are written than fit in the array,CodedOutputStream.OutOfSpaceExceptionwill be thrown. Writing directly to a flat array is faster than writing to anOutputStream. See alsoByteString.newCodedBuilder(int).
-
newInstance
public static CodedOutputStream newInstance(byte[] flatArray, int offset, int length)
Create a newCodedOutputStreamthat writes directly to the given byte array slice. If more bytes are written than fit in the slice,CodedOutputStream.OutOfSpaceExceptionwill be thrown. Writing directly to a flat array is faster than writing to anOutputStream. See alsoByteString.newCodedBuilder(int).
-
newInstance
public static CodedOutputStream newInstance(java.nio.ByteBuffer buffer)
Create a newCodedOutputStreamthat writes to the givenByteBuffer.
-
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.
-
newInstance
@Deprecated public static CodedOutputStream newInstance(java.nio.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 aByteBuffer. UsenewInstance(ByteBuffer)instead.Create a newCodedOutputStreamthat writes to the givenByteBuffer.
-
writeTag
public abstract void writeTag(int fieldNumber, int wireType) throws java.io.IOExceptionEncode and write a tag.- Throws:
java.io.IOException
-
writeInt32
public abstract void writeInt32(int fieldNumber, int value) throws java.io.IOExceptionWrite anint32field, including tag, to the stream.- Throws:
java.io.IOException
-
writeUInt32
public abstract void writeUInt32(int fieldNumber, int value) throws java.io.IOExceptionWrite auint32field, including tag, to the stream.- Throws:
java.io.IOException
-
writeSInt32
public final void writeSInt32(int fieldNumber, int value) throws java.io.IOExceptionWrite asint32field, including tag, to the stream.- Throws:
java.io.IOException
-
writeFixed32
public abstract void writeFixed32(int fieldNumber, int value) throws java.io.IOExceptionWrite afixed32field, including tag, to the stream.- Throws:
java.io.IOException
-
writeSFixed32
public final void writeSFixed32(int fieldNumber, int value) throws java.io.IOExceptionWrite ansfixed32field, including tag, to the stream.- Throws:
java.io.IOException
-
writeInt64
public final void writeInt64(int fieldNumber, long value) throws java.io.IOExceptionWrite anint64field, including tag, to the stream.- Throws:
java.io.IOException
-
writeUInt64
public abstract void writeUInt64(int fieldNumber, long value) throws java.io.IOExceptionWrite auint64field, including tag, to the stream.- Throws:
java.io.IOException
-
writeSInt64
public final void writeSInt64(int fieldNumber, long value) throws java.io.IOExceptionWrite ansint64field, including tag, to the stream.- Throws:
java.io.IOException
-
writeFixed64
public abstract void writeFixed64(int fieldNumber, long value) throws java.io.IOExceptionWrite afixed64field, including tag, to the stream.- Throws:
java.io.IOException
-
writeSFixed64
public final void writeSFixed64(int fieldNumber, long value) throws java.io.IOExceptionWrite ansfixed64field, including tag, to the stream.- Throws:
java.io.IOException
-
writeFloat
public final void writeFloat(int fieldNumber, float value) throws java.io.IOExceptionWrite afloatfield, including tag, to the stream.- Throws:
java.io.IOException
-
writeDouble
public final void writeDouble(int fieldNumber, double value) throws java.io.IOExceptionWrite adoublefield, including tag, to the stream.- Throws:
java.io.IOException
-
writeBool
public abstract void writeBool(int fieldNumber, boolean value) throws java.io.IOExceptionWrite aboolfield, including tag, to the stream.- Throws:
java.io.IOException
-
writeEnum
public final void writeEnum(int fieldNumber, int value) throws java.io.IOExceptionWrite 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:
java.io.IOException
-
writeString
public abstract void writeString(int fieldNumber, java.lang.String value) throws java.io.IOExceptionWrite astringfield, including tag, to the stream.- Throws:
java.io.IOException
-
writeBytes
public abstract void writeBytes(int fieldNumber, ByteString value) throws java.io.IOExceptionWrite abytesfield, including tag, to the stream.- Throws:
java.io.IOException
-
writeByteArray
public abstract void writeByteArray(int fieldNumber, byte[] value) throws java.io.IOExceptionWrite abytesfield, including tag, to the stream.- Throws:
java.io.IOException
-
writeByteArray
public abstract void writeByteArray(int fieldNumber, byte[] value, int offset, int length) throws java.io.IOExceptionWrite abytesfield, including tag, to the stream.- Throws:
java.io.IOException
-
writeByteBuffer
public abstract void writeByteBuffer(int fieldNumber, java.nio.ByteBuffer value) throws java.io.IOExceptionWrite abytesfield, 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 callwriteByteBuffer(fieldNumber, byteBuffer.slice()).- Throws:
java.io.IOException
-
writeRawByte
public final void writeRawByte(byte value) throws java.io.IOExceptionWrite a single byte.- Throws:
java.io.IOException
-
writeRawByte
public final void writeRawByte(int value) throws java.io.IOExceptionWrite a single byte, represented by an integer value.- Throws:
java.io.IOException
-
writeRawBytes
public final void writeRawBytes(byte[] value) throws java.io.IOExceptionWrite an array of bytes.- Throws:
java.io.IOException
-
writeRawBytes
public final void writeRawBytes(byte[] value, int offset, int length) throws java.io.IOExceptionWrite part of an array of bytes.- Throws:
java.io.IOException
-
writeRawBytes
public final void writeRawBytes(ByteString value) throws java.io.IOException
Write a byte string.- Throws:
java.io.IOException
-
writeRawBytes
public abstract void writeRawBytes(java.nio.ByteBuffer value) throws java.io.IOExceptionWrite 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 callwriteRawBytes(byteBuffer.slice()).- Throws:
java.io.IOException
-
writeMessage
public abstract void writeMessage(int fieldNumber, MessageLite value) throws java.io.IOExceptionWrite an embedded message field, including tag, to the stream.- Throws:
java.io.IOException
-
writeMessageSetExtension
public abstract void writeMessageSetExtension(int fieldNumber, MessageLite value) throws java.io.IOExceptionWrite a MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.- Throws:
java.io.IOException
-
writeRawMessageSetExtension
public abstract void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws java.io.IOExceptionWrite an unparsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.- Throws:
java.io.IOException
-
writeInt32NoTag
public abstract void writeInt32NoTag(int value) throws java.io.IOExceptionWrite anint32field to the stream.- Throws:
java.io.IOException
-
writeUInt32NoTag
public abstract void writeUInt32NoTag(int value) throws java.io.IOExceptionWrite auint32field to the stream.- Throws:
java.io.IOException
-
writeSInt32NoTag
public final void writeSInt32NoTag(int value) throws java.io.IOExceptionWrite asint32field to the stream.- Throws:
java.io.IOException
-
writeFixed32NoTag
public abstract void writeFixed32NoTag(int value) throws java.io.IOExceptionWrite afixed32field to the stream.- Throws:
java.io.IOException
-
writeSFixed32NoTag
public final void writeSFixed32NoTag(int value) throws java.io.IOExceptionWrite asfixed32field to the stream.- Throws:
java.io.IOException
-
writeInt64NoTag
public final void writeInt64NoTag(long value) throws java.io.IOExceptionWrite anint64field to the stream.- Throws:
java.io.IOException
-
writeUInt64NoTag
public abstract void writeUInt64NoTag(long value) throws java.io.IOExceptionWrite auint64field to the stream.- Throws:
java.io.IOException
-
writeSInt64NoTag
public final void writeSInt64NoTag(long value) throws java.io.IOExceptionWrite asint64field to the stream.- Throws:
java.io.IOException
-
writeFixed64NoTag
public abstract void writeFixed64NoTag(long value) throws java.io.IOExceptionWrite afixed64field to the stream.- Throws:
java.io.IOException
-
writeSFixed64NoTag
public final void writeSFixed64NoTag(long value) throws java.io.IOExceptionWrite asfixed64field to the stream.- Throws:
java.io.IOException
-
writeFloatNoTag
public final void writeFloatNoTag(float value) throws java.io.IOExceptionWrite afloatfield to the stream.- Throws:
java.io.IOException
-
writeDoubleNoTag
public final void writeDoubleNoTag(double value) throws java.io.IOExceptionWrite adoublefield to the stream.- Throws:
java.io.IOException
-
writeBoolNoTag
public final void writeBoolNoTag(boolean value) throws java.io.IOExceptionWrite aboolfield to the stream.- Throws:
java.io.IOException
-
writeEnumNoTag
public final void writeEnumNoTag(int value) throws java.io.IOExceptionWrite 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:
java.io.IOException
-
writeStringNoTag
public abstract void writeStringNoTag(java.lang.String value) throws java.io.IOExceptionWrite astringfield to the stream.- Throws:
java.io.IOException
-
writeBytesNoTag
public abstract void writeBytesNoTag(ByteString value) throws java.io.IOException
Write abytesfield to the stream.- Throws:
java.io.IOException
-
writeByteArrayNoTag
public final void writeByteArrayNoTag(byte[] value) throws java.io.IOExceptionWrite abytesfield to the stream.- Throws:
java.io.IOException
-
writeMessageNoTag
public abstract void writeMessageNoTag(MessageLite value) throws java.io.IOException
Write an embedded message field to the stream.- Throws:
java.io.IOException
-
write
@ExperimentalApi public abstract void write(byte value) throws java.io.IOException
Description copied from class:ByteOutputWrites a single byte.- Specified by:
writein classByteOutput- Parameters:
value- the byte to be written- Throws:
java.io.IOException- thrown if an error occurred while writing
-
write
@ExperimentalApi public abstract void write(byte[] value, int offset, int length) throws java.io.IOException
Description copied from class:ByteOutputWrites a sequence of bytes. TheByteOutputmust copyvalueif it will not be processed prior to the return of this method call, sincevaluemay 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:
writein classByteOutput- Parameters:
value- the bytes to be writtenoffset- the offset of the start of the writable rangelength- the number of bytes to write starting fromoffset- Throws:
java.io.IOException- thrown if an error occurred while writing
-
writeLazy
@ExperimentalApi public abstract void writeLazy(byte[] value, int offset, int length) throws java.io.IOException
Description copied from class:ByteOutputWrites a sequence of bytes. TheByteOutputis 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:
writeLazyin classByteOutput- Parameters:
value- the bytes to be writtenoffset- the offset of the start of the writable rangelength- the number of bytes to write starting fromoffset- Throws:
java.io.IOException- thrown if an error occurred while writing
-
write
public abstract void write(java.nio.ByteBuffer value) throws java.io.IOExceptionDescription copied from class:ByteOutputWrites a sequence of bytes. TheByteOutputmust copyvalueif it will not be processed prior to the return of this method call, sincevaluemay 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:
writein classByteOutput- Parameters:
value- the bytes to be written. Upon returning from this call, thepositionof this buffer will be set to thelimit- Throws:
java.io.IOException- thrown if an error occurred while writing
-
writeLazy
@ExperimentalApi public abstract void writeLazy(java.nio.ByteBuffer value) throws java.io.IOException
Description copied from class:ByteOutputWrites a sequence of bytes. TheByteOutputis 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:
writeLazyin classByteOutput- Parameters:
value- the bytes to be written. Upon returning from this call, thepositionof this buffer will be set to thelimit- Throws:
java.io.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 anint32field, including tag.
-
computeUInt32Size
public static int computeUInt32Size(int fieldNumber, int value)Compute the number of bytes that would be needed to encode auint32field, including tag.
-
computeSInt32Size
public static int computeSInt32Size(int fieldNumber, int value)Compute the number of bytes that would be needed to encode ansint32field, including tag.
-
computeFixed32Size
public static int computeFixed32Size(int fieldNumber, int value)Compute the number of bytes that would be needed to encode afixed32field, including tag.
-
computeSFixed32Size
public static int computeSFixed32Size(int fieldNumber, int value)Compute the number of bytes that would be needed to encode ansfixed32field, including tag.
-
computeInt64Size
public static int computeInt64Size(int fieldNumber, long value)Compute the number of bytes that would be needed to encode anint64field, including tag.
-
computeUInt64Size
public static int computeUInt64Size(int fieldNumber, long value)Compute the number of bytes that would be needed to encode auint64field, including tag.
-
computeSInt64Size
public static int computeSInt64Size(int fieldNumber, long value)Compute the number of bytes that would be needed to encode ansint64field, including tag.
-
computeFixed64Size
public static int computeFixed64Size(int fieldNumber, long value)Compute the number of bytes that would be needed to encode afixed64field, including tag.
-
computeSFixed64Size
public static int computeSFixed64Size(int fieldNumber, long value)Compute the number of bytes that would be needed to encode ansfixed64field, including tag.
-
computeFloatSize
public static int computeFloatSize(int fieldNumber, float value)Compute the number of bytes that would be needed to encode afloatfield, including tag.
-
computeDoubleSize
public static int computeDoubleSize(int fieldNumber, double value)Compute the number of bytes that would be needed to encode adoublefield, including tag.
-
computeBoolSize
public static int computeBoolSize(int fieldNumber, boolean value)Compute the number of bytes that would be needed to encode aboolfield, 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, java.lang.String value)Compute the number of bytes that would be needed to encode astringfield, including tag.
-
computeBytesSize
public static int computeBytesSize(int fieldNumber, ByteString value)Compute the number of bytes that would be needed to encode abytesfield, including tag.
-
computeByteArraySize
public static int computeByteArraySize(int fieldNumber, byte[] value)Compute the number of bytes that would be needed to encode abytesfield, including tag.
-
computeByteBufferSize
public static int computeByteBufferSize(int fieldNumber, java.nio.ByteBuffer value)Compute the number of bytes that would be needed to encode abytesfield, 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.
-
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 anint32field, including tag.
-
computeUInt32SizeNoTag
public static int computeUInt32SizeNoTag(int value)
Compute the number of bytes that would be needed to encode auint32field.
-
computeSInt32SizeNoTag
public static int computeSInt32SizeNoTag(int value)
Compute the number of bytes that would be needed to encode ansint32field.
-
computeFixed32SizeNoTag
public static int computeFixed32SizeNoTag(int unused)
Compute the number of bytes that would be needed to encode afixed32field.
-
computeSFixed32SizeNoTag
public static int computeSFixed32SizeNoTag(int unused)
Compute the number of bytes that would be needed to encode ansfixed32field.
-
computeInt64SizeNoTag
public static int computeInt64SizeNoTag(long value)
Compute the number of bytes that would be needed to encode anint64field, including tag.
-
computeUInt64SizeNoTag
public static int computeUInt64SizeNoTag(long value)
Compute the number of bytes that would be needed to encode auint64field, including tag.
-
computeSInt64SizeNoTag
public static int computeSInt64SizeNoTag(long value)
Compute the number of bytes that would be needed to encode ansint64field.
-
computeFixed64SizeNoTag
public static int computeFixed64SizeNoTag(long unused)
Compute the number of bytes that would be needed to encode afixed64field.
-
computeSFixed64SizeNoTag
public static int computeSFixed64SizeNoTag(long unused)
Compute the number of bytes that would be needed to encode ansfixed64field.
-
computeFloatSizeNoTag
public static int computeFloatSizeNoTag(float unused)
Compute the number of bytes that would be needed to encode afloatfield, including tag.
-
computeDoubleSizeNoTag
public static int computeDoubleSizeNoTag(double unused)
Compute the number of bytes that would be needed to encode adoublefield, including tag.
-
computeBoolSizeNoTag
public static int computeBoolSizeNoTag(boolean unused)
Compute the number of bytes that would be needed to encode aboolfield.
-
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(java.lang.String value)
Compute the number of bytes that would be needed to encode astringfield.
-
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 abytesfield.
-
computeByteArraySizeNoTag
public static int computeByteArraySizeNoTag(byte[] value)
Compute the number of bytes that would be needed to encode abytesfield.
-
computeByteBufferSizeNoTag
public static int computeByteBufferSizeNoTag(java.nio.ByteBuffer value)
Compute the number of bytes that would be needed to encode abytesfield.
-
computeMessageSizeNoTag
public static int computeMessageSizeNoTag(MessageLite value)
Compute the number of bytes that would be needed to encode an embedded message field.
-
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 java.io.IOExceptionFlushes the stream and forces any buffered bytes to be written. This does not flush the underlying OutputStream.- Throws:
java.io.IOException
-
spaceLeft
public abstract int spaceLeft()
If writing to a flat array, return the space left in the array. Otherwise, throwsUnsupportedOperationException.
-
checkNoSpaceLeft
public final void checkNoSpaceLeft()
Verifies thatspaceLeft()returns zero. It's common to create a byte array that is exactly big enough to hold a message, then write to it with aCodedOutputStream. CallingcheckNoSpaceLeft()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.
-
writeGroup
@Deprecated public final void writeGroup(int fieldNumber, MessageLite value) throws java.io.IOExceptionDeprecated.groups are deprecated.Write agroupfield, including tag, to the stream.- Throws:
java.io.IOException
-
writeGroupNoTag
@Deprecated public final void writeGroupNoTag(MessageLite value) throws java.io.IOException
Deprecated.groups are deprecated.Write agroupfield to the stream.- Throws:
java.io.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 agroupfield, including tag.
-
computeGroupSizeNoTag
@Deprecated @InlineMe(replacement="value.getSerializedSize()") public static int computeGroupSizeNoTag(MessageLite value)
Deprecated.Compute the number of bytes that would be needed to encode agroupfield.
-
writeRawVarint32
@Deprecated @InlineMe(replacement="this.writeUInt32NoTag(value)") public final void writeRawVarint32(int value) throws java.io.IOExceptionDeprecated.usewriteUInt32NoTag(int)instead.Encode and write a varint.valueis treated as unsigned, so it won't be sign-extended if negative.- Throws:
java.io.IOException
-
writeRawVarint64
@Deprecated @InlineMe(replacement="this.writeUInt64NoTag(value)") public final void writeRawVarint64(long value) throws java.io.IOExceptionDeprecated.usewriteUInt64NoTag(long)instead.Encode and write a varint.- Throws:
java.io.IOException
-
computeRawVarint32Size
@Deprecated @InlineMe(replacement="CodedOutputStream.computeUInt32SizeNoTag(value)", imports="com.google.protobuf.CodedOutputStream") public static int computeRawVarint32Size(int value)Deprecated.usecomputeUInt32SizeNoTag(int)instead.Compute the number of bytes that would be needed to encode a varint.valueis treated as unsigned, so it won't be sign-extended if negative.
-
computeRawVarint64Size
@Deprecated @InlineMe(replacement="CodedOutputStream.computeUInt64SizeNoTag(value)", imports="com.google.protobuf.CodedOutputStream") public static int computeRawVarint64Size(long value)Deprecated.usecomputeUInt64SizeNoTag(long)instead.Compute the number of bytes that would be needed to encode a varint.
-
writeRawLittleEndian32
@Deprecated @InlineMe(replacement="this.writeFixed32NoTag(value)") public final void writeRawLittleEndian32(int value) throws java.io.IOExceptionDeprecated.UsewriteFixed32NoTag(int)instead.Write a little-endian 32-bit integer.- Throws:
java.io.IOException
-
writeRawLittleEndian64
@Deprecated @InlineMe(replacement="this.writeFixed64NoTag(value)") public final void writeRawLittleEndian64(long value) throws java.io.IOExceptionDeprecated.UsewriteFixed64NoTag(long)instead.Write a little-endian 64-bit integer.- Throws:
java.io.IOException
-
-