Package com.google.protobuf
Class CodedOutputStream
java.lang.Object
com.google.protobuf.CodedOutputStream
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 ClassesModifier and TypeClassDescriptionstatic class
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
FieldsModifier and TypeFieldDescriptionstatic final int
The buffer size used innewInstance(OutputStream)
.static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Verifies thatspaceLeft()
returns zero.static int
computeBoolSize
(int fieldNumber, boolean value) Compute the number of bytes that would be needed to encode abool
field, including tag.static int
computeBoolSizeNoTag
(boolean value) Compute the number of bytes that would be needed to encode abool
field.static int
computeByteArraySize
(int fieldNumber, byte[] value) Compute the number of bytes that would be needed to encode abytes
field, including tag.static int
computeByteArraySizeNoTag
(byte[] value) Compute the number of bytes that would be needed to encode abytes
field.static int
computeByteBufferSize
(int fieldNumber, ByteBuffer value) Compute the number of bytes that would be needed to encode abytes
field, including tag.static int
Compute the number of bytes that would be needed to encode abytes
field.static int
computeBytesSize
(int fieldNumber, ByteString value) Compute the number of bytes that would be needed to encode abytes
field, including tag.static int
computeBytesSizeNoTag
(ByteString value) Compute the number of bytes that would be needed to encode abytes
field.static int
computeDoubleSize
(int fieldNumber, double value) Compute the number of bytes that would be needed to encode adouble
field, including tag.static int
computeDoubleSizeNoTag
(double value) Compute the number of bytes that would be needed to encode adouble
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 afixed32
field, including tag.static int
computeFixed32SizeNoTag
(int value) Compute the number of bytes that would be needed to encode afixed32
field.static int
computeFixed64Size
(int fieldNumber, long value) Compute the number of bytes that would be needed to encode afixed64
field, including tag.static int
computeFixed64SizeNoTag
(long value) Compute the number of bytes that would be needed to encode afixed64
field.static int
computeFloatSize
(int fieldNumber, float value) Compute the number of bytes that would be needed to encode afloat
field, including tag.static int
computeFloatSizeNoTag
(float value) Compute the number of bytes that would be needed to encode afloat
field, including tag.static int
computeGroupSize
(int fieldNumber, MessageLite value) Compute the number of bytes that would be needed to encode agroup
field, including tag.static int
computeGroupSizeNoTag
(MessageLite value) Compute the number of bytes that would be needed to encode agroup
field.static int
computeInt32Size
(int fieldNumber, int value) Compute the number of bytes that would be needed to encode anint32
field, including tag.static int
computeInt32SizeNoTag
(int value) Compute the number of bytes that would be needed to encode anint32
field, including tag.static int
computeInt64Size
(int fieldNumber, long value) Compute the number of bytes that would be needed to encode anint64
field, including tag.static int
computeInt64SizeNoTag
(long value) Compute the number of bytes that would be needed to encode anint64
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
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
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 ansfixed32
field, including tag.static int
computeSFixed32SizeNoTag
(int value) Compute the number of bytes that would be needed to encode ansfixed32
field.static int
computeSFixed64Size
(int fieldNumber, long value) Compute the number of bytes that would be needed to encode ansfixed64
field, including tag.static int
computeSFixed64SizeNoTag
(long value) Compute the number of bytes that would be needed to encode ansfixed64
field.static int
computeSInt32Size
(int fieldNumber, int value) Compute the number of bytes that would be needed to encode ansint32
field, including tag.static int
computeSInt32SizeNoTag
(int value) Compute the number of bytes that would be needed to encode ansint32
field.static int
computeSInt64Size
(int fieldNumber, long value) Compute the number of bytes that would be needed to encode ansint64
field, including tag.static int
computeSInt64SizeNoTag
(long value) Compute the number of bytes that would be needed to encode ansint64
field.static int
computeStringSize
(int fieldNumber, String value) Compute the number of bytes that would be needed to encode astring
field, including tag.static int
computeStringSizeNoTag
(String value) Compute the number of bytes that would be needed to encode astring
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 auint32
field, including tag.static int
computeUInt32SizeNoTag
(int value) Compute the number of bytes that would be needed to encode auint32
field.static int
computeUInt64Size
(int fieldNumber, long value) Compute the number of bytes that would be needed to encode auint64
field, including tag.static int
computeUInt64SizeNoTag
(long value) Compute the number of bytes that would be needed to encode auint64
field, including tag.static int
computeUnknownGroupSize
(int fieldNumber, MessageLite value) Deprecated.static int
Deprecated.UnknownFieldSet now implements MessageLite, so you can just callcomputeUnknownGroupSizeNoTag(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
Get the total number of bytes successfully written to this stream.static CodedOutputStream
newInstance
(byte[] flatArray) Create a newCodedOutputStream
that writes directly to the given byte array.static CodedOutputStream
newInstance
(byte[] flatArray, int offset, int length) Create a newCodedOutputStream
that writes directly to the given byte array slice.static CodedOutputStream
newInstance
(OutputStream output) Create a newCodedOutputStream
wrapping the givenOutputStream
.static CodedOutputStream
newInstance
(OutputStream output, int bufferSize) Create a newCodedOutputStream
wrapping the givenOutputStream
with a given buffer size.static CodedOutputStream
newInstance
(ByteBuffer byteBuffer) Create a newCodedOutputStream
that writes to the given ByteBuffer.static CodedOutputStream
newInstance
(ByteBuffer byteBuffer, int bufferSize) Create a newCodedOutputStream
that writes to the given ByteBuffer.int
If writing to a flat array, return the space left in the array.void
writeBool
(int fieldNumber, boolean value) Write abool
field, including tag, to the stream.void
writeBoolNoTag
(boolean value) Write abool
field to the stream.void
writeByteArray
(int fieldNumber, byte[] value) Write abytes
field, including tag, to the stream.void
writeByteArray
(int fieldNumber, byte[] value, int offset, int length) Write abytes
field, including tag, to the stream.void
writeByteArrayNoTag
(byte[] value) Write abytes
field to the stream.void
writeByteArrayNoTag
(byte[] value, int offset, int length) Write abytes
field to the stream.void
writeByteBuffer
(int fieldNumber, ByteBuffer value) Write abytes
field, including tag, to the stream.void
writeByteBufferNoTag
(ByteBuffer value) Write abytes
field to the stream.void
writeBytes
(int fieldNumber, ByteString value) Write abytes
field, including tag, to the stream.void
writeBytesNoTag
(ByteString value) Write abytes
field to the stream.void
writeDouble
(int fieldNumber, double value) Write adouble
field, including tag, to the stream.void
writeDoubleNoTag
(double value) Write adouble
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 afixed32
field, including tag, to the stream.void
writeFixed32NoTag
(int value) Write afixed32
field to the stream.void
writeFixed64
(int fieldNumber, long value) Write afixed64
field, including tag, to the stream.void
writeFixed64NoTag
(long value) Write afixed64
field to the stream.void
writeFloat
(int fieldNumber, float value) Write afloat
field, including tag, to the stream.void
writeFloatNoTag
(float value) Write afloat
field to the stream.void
writeGroup
(int fieldNumber, MessageLite value) Write agroup
field, including tag, to the stream.void
writeGroupNoTag
(MessageLite value) Write agroup
field to the stream.void
writeInt32
(int fieldNumber, int value) Write anint32
field, including tag, to the stream.void
writeInt32NoTag
(int value) Write anint32
field to the stream.void
writeInt64
(int fieldNumber, long value) Write anint64
field, including tag, to the stream.void
writeInt64NoTag
(long value) Write anint64
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
(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 ansfixed32
field, including tag, to the stream.void
writeSFixed32NoTag
(int value) Write ansfixed32
field to the stream.void
writeSFixed64
(int fieldNumber, long value) Write ansfixed64
field, including tag, to the stream.void
writeSFixed64NoTag
(long value) Write ansfixed64
field to the stream.void
writeSInt32
(int fieldNumber, int value) Write ansint32
field, including tag, to the stream.void
writeSInt32NoTag
(int value) Write ansint32
field to the stream.void
writeSInt64
(int fieldNumber, long value) Write ansint64
field, including tag, to the stream.void
writeSInt64NoTag
(long value) Write ansint64
field to the stream.void
writeString
(int fieldNumber, String value) Write astring
field, including tag, to the stream.void
writeStringNoTag
(String value) Write astring
field to the stream.void
writeTag
(int fieldNumber, int wireType) Encode and write a tag.void
writeUInt32
(int fieldNumber, int value) Write auint32
field, including tag, to the stream.void
writeUInt32NoTag
(int value) Write auint32
field to the stream.void
writeUInt64
(int fieldNumber, long value) Write auint64
field, including tag, to the stream.void
writeUInt64NoTag
(long value) Write auint64
field to the stream.void
writeUnknownGroup
(int fieldNumber, MessageLite value) Deprecated.UnknownFieldSet now implements MessageLite, so you can just callwriteGroup(int, com.google.protobuf.MessageLite)
.void
Deprecated.UnknownFieldSet now implements MessageLite, so you can just callwriteGroupNoTag(com.google.protobuf.MessageLite)
.
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEThe buffer size used innewInstance(OutputStream)
.- See Also:
-
LITTLE_ENDIAN_32_SIZE
public static final int LITTLE_ENDIAN_32_SIZE- See Also:
-
LITTLE_ENDIAN_64_SIZE
public static final int LITTLE_ENDIAN_64_SIZE- See Also:
-
-
Method Details
-
newInstance
Create a newCodedOutputStream
wrapping the givenOutputStream
. -
newInstance
Create a newCodedOutputStream
wrapping the givenOutputStream
with a given buffer size. -
newInstance
Create a newCodedOutputStream
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 anOutputStream
. See alsoByteString.newCodedBuilder(int)
. -
newInstance
Create a newCodedOutputStream
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 anOutputStream
. See alsoByteString.newCodedBuilder(int)
. -
newInstance
Create a newCodedOutputStream
that writes to the given ByteBuffer. -
newInstance
Create a newCodedOutputStream
that writes to the given ByteBuffer. -
writeDouble
Write adouble
field, including tag, to the stream.- Throws:
IOException
-
writeFloat
Write afloat
field, including tag, to the stream.- Throws:
IOException
-
writeUInt64
Write auint64
field, including tag, to the stream.- Throws:
IOException
-
writeInt64
Write anint64
field, including tag, to the stream.- Throws:
IOException
-
writeInt32
Write anint32
field, including tag, to the stream.- Throws:
IOException
-
writeFixed64
Write afixed64
field, including tag, to the stream.- Throws:
IOException
-
writeFixed32
Write afixed32
field, including tag, to the stream.- Throws:
IOException
-
writeBool
Write abool
field, including tag, to the stream.- Throws:
IOException
-
writeString
Write astring
field, including tag, to the stream.- Throws:
IOException
-
writeGroup
Write agroup
field, including tag, to the stream.- Throws:
IOException
-
writeUnknownGroup
Deprecated.UnknownFieldSet now implements MessageLite, so you can just callwriteGroup(int, com.google.protobuf.MessageLite)
.Write a group represented by anUnknownFieldSet
.- Throws:
IOException
-
writeMessage
Write an embedded message field, including tag, to the stream.- Throws:
IOException
-
writeBytes
Write abytes
field, including tag, to the stream.- Throws:
IOException
-
writeByteArray
Write abytes
field, including tag, to the stream.- Throws:
IOException
-
writeByteArray
public void writeByteArray(int fieldNumber, byte[] value, int offset, int length) throws IOException Write abytes
field, including tag, to the stream.- Throws:
IOException
-
writeByteBuffer
Write abytes
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 callwriteByteBuffer(fieldNumber, byteBuffer.slice())
.- Throws:
IOException
-
writeUInt32
Write auint32
field, including tag, to the stream.- Throws:
IOException
-
writeEnum
Write an enum field, including tag, to the stream. Caller is responsible for converting the enum value to its numeric value.- Throws:
IOException
-
writeSFixed32
Write ansfixed32
field, including tag, to the stream.- Throws:
IOException
-
writeSFixed64
Write ansfixed64
field, including tag, to the stream.- Throws:
IOException
-
writeSInt32
Write ansint32
field, including tag, to the stream.- Throws:
IOException
-
writeSInt64
Write ansint64
field, including tag, to the stream.- Throws:
IOException
-
writeMessageSetExtension
Write a MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.- Throws:
IOException
-
writeRawMessageSetExtension
Write an unparsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.- Throws:
IOException
-
writeDoubleNoTag
Write adouble
field to the stream.- Throws:
IOException
-
writeFloatNoTag
Write afloat
field to the stream.- Throws:
IOException
-
writeUInt64NoTag
Write auint64
field to the stream.- Throws:
IOException
-
writeInt64NoTag
Write anint64
field to the stream.- Throws:
IOException
-
writeInt32NoTag
Write anint32
field to the stream.- Throws:
IOException
-
writeFixed64NoTag
Write afixed64
field to the stream.- Throws:
IOException
-
writeFixed32NoTag
Write afixed32
field to the stream.- Throws:
IOException
-
writeBoolNoTag
Write abool
field to the stream.- Throws:
IOException
-
writeStringNoTag
Write astring
field to the stream.- Throws:
IOException
-
writeGroupNoTag
Write agroup
field to the stream.- Throws:
IOException
-
writeUnknownGroupNoTag
Deprecated.UnknownFieldSet now implements MessageLite, so you can just callwriteGroupNoTag(com.google.protobuf.MessageLite)
.Write a group represented by anUnknownFieldSet
.- Throws:
IOException
-
writeMessageNoTag
Write an embedded message field to the stream.- Throws:
IOException
-
writeBytesNoTag
Write abytes
field to the stream.- Throws:
IOException
-
writeByteArrayNoTag
Write abytes
field to the stream.- Throws:
IOException
-
writeByteArrayNoTag
Write abytes
field to the stream.- Throws:
IOException
-
writeByteBufferNoTag
Write abytes
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 callwriteByteBufferNoTag(byteBuffer.slice())
.- Throws:
IOException
-
writeUInt32NoTag
Write auint32
field to the stream.- Throws:
IOException
-
writeEnumNoTag
Write an enum field to the stream. Caller is responsible for converting the enum value to its numeric value.- Throws:
IOException
-
writeSFixed32NoTag
Write ansfixed32
field to the stream.- Throws:
IOException
-
writeSFixed64NoTag
Write ansfixed64
field to the stream.- Throws:
IOException
-
writeSInt32NoTag
Write ansint32
field to the stream.- Throws:
IOException
-
writeSInt64NoTag
Write ansint64
field to the stream.- Throws:
IOException
-
computeDoubleSize
public static int computeDoubleSize(int fieldNumber, double value) Compute the number of bytes that would be needed to encode adouble
field, including tag. -
computeFloatSize
public static int computeFloatSize(int fieldNumber, float value) Compute the number of bytes that would be needed to encode afloat
field, including tag. -
computeUInt64Size
public static int computeUInt64Size(int fieldNumber, long value) Compute the number of bytes that would be needed to encode auint64
field, including tag. -
computeInt64Size
public static int computeInt64Size(int fieldNumber, long value) Compute the number of bytes that would be needed to encode anint64
field, including tag. -
computeInt32Size
public static int computeInt32Size(int fieldNumber, int value) Compute the number of bytes that would be needed to encode anint32
field, including tag. -
computeFixed64Size
public static int computeFixed64Size(int fieldNumber, long value) Compute the number of bytes that would be needed to encode afixed64
field, including tag. -
computeFixed32Size
public static int computeFixed32Size(int fieldNumber, int value) Compute the number of bytes that would be needed to encode afixed32
field, including tag. -
computeBoolSize
public static int computeBoolSize(int fieldNumber, boolean value) Compute the number of bytes that would be needed to encode abool
field, including tag. -
computeStringSize
Compute the number of bytes that would be needed to encode astring
field, including tag. -
computeGroupSize
Compute the number of bytes that would be needed to encode agroup
field, including tag. -
computeUnknownGroupSize
Deprecated.UnknownFieldSet now implements MessageLite, so you can just callcomputeGroupSize(int, com.google.protobuf.MessageLite)
.Compute the number of bytes that would be needed to encode agroup
field represented by anUnknownFieldSet
, including tag. -
computeMessageSize
Compute the number of bytes that would be needed to encode an embedded message field, including tag. -
computeBytesSize
Compute the number of bytes that would be needed to encode abytes
field, including tag. -
computeByteArraySize
public static int computeByteArraySize(int fieldNumber, byte[] value) Compute the number of bytes that would be needed to encode abytes
field, including tag. -
computeByteBufferSize
Compute the number of bytes that would be needed to encode abytes
field, including tag. -
computeLazyFieldSize
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 auint32
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 ansfixed32
field, including tag. -
computeSFixed64Size
public static int computeSFixed64Size(int fieldNumber, long value) Compute the number of bytes that would be needed to encode ansfixed64
field, including tag. -
computeSInt32Size
public static int computeSInt32Size(int fieldNumber, int value) Compute the number of bytes that would be needed to encode ansint32
field, including tag. -
computeSInt64Size
public static int computeSInt64Size(int fieldNumber, long value) Compute the number of bytes that would be needed to encode ansint64
field, including tag. -
computeMessageSetExtensionSize
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
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
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 adouble
field, including tag. -
computeFloatSizeNoTag
public static int computeFloatSizeNoTag(float value) Compute the number of bytes that would be needed to encode afloat
field, including tag. -
computeUInt64SizeNoTag
public static int computeUInt64SizeNoTag(long value) Compute the number of bytes that would be needed to encode auint64
field, including tag. -
computeInt64SizeNoTag
public static int computeInt64SizeNoTag(long value) Compute the number of bytes that would be needed to encode anint64
field, including tag. -
computeInt32SizeNoTag
public static int computeInt32SizeNoTag(int value) Compute the number of bytes that would be needed to encode anint32
field, including tag. -
computeFixed64SizeNoTag
public static int computeFixed64SizeNoTag(long value) Compute the number of bytes that would be needed to encode afixed64
field. -
computeFixed32SizeNoTag
public static int computeFixed32SizeNoTag(int value) Compute the number of bytes that would be needed to encode afixed32
field. -
computeBoolSizeNoTag
public static int computeBoolSizeNoTag(boolean value) Compute the number of bytes that would be needed to encode abool
field. -
computeStringSizeNoTag
Compute the number of bytes that would be needed to encode astring
field. -
computeGroupSizeNoTag
Compute the number of bytes that would be needed to encode agroup
field. -
computeUnknownGroupSizeNoTag
Deprecated.UnknownFieldSet now implements MessageLite, so you can just callcomputeUnknownGroupSizeNoTag(com.google.protobuf.MessageLite)
.Compute the number of bytes that would be needed to encode agroup
field represented by anUnknownFieldSet
, including tag. -
computeMessageSizeNoTag
Compute the number of bytes that would be needed to encode an embedded message field. -
computeLazyFieldSizeNoTag
Compute the number of bytes that would be needed to encode an embedded message stored in lazy field. -
computeBytesSizeNoTag
Compute the number of bytes that would be needed to encode abytes
field. -
computeByteArraySizeNoTag
public static int computeByteArraySizeNoTag(byte[] value) Compute the number of bytes that would be needed to encode abytes
field. -
computeByteBufferSizeNoTag
Compute the number of bytes that would be needed to encode abytes
field. -
computeUInt32SizeNoTag
public static int computeUInt32SizeNoTag(int value) Compute the number of bytes that would be needed to encode auint32
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 ansfixed32
field. -
computeSFixed64SizeNoTag
public static int computeSFixed64SizeNoTag(long value) Compute the number of bytes that would be needed to encode ansfixed64
field. -
computeSInt32SizeNoTag
public static int computeSInt32SizeNoTag(int value) Compute the number of bytes that would be needed to encode ansint32
field. -
computeSInt64SizeNoTag
public static int computeSInt64SizeNoTag(long value) Compute the number of bytes that would be needed to encode ansint64
field. -
flush
Flushes the stream and forces any buffered bytes to be written. This does not flush the underlying OutputStream.- Throws:
IOException
-
spaceLeft
public int spaceLeft()If writing to a flat array, return the space left in the array. Otherwise, throwsUnsupportedOperationException
. -
checkNoSpaceLeft
public 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 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
Write a single byte.- Throws:
IOException
-
writeRawByte
Write a single byte, represented by an integer value.- Throws:
IOException
-
writeRawBytes
Write a byte string.- Throws:
IOException
-
writeRawBytes
Write an array of bytes.- Throws:
IOException
-
writeRawBytes
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 callwriteRawBytes(byteBuffer.slice())
.- Throws:
IOException
-
writeRawBytes
Write part of an array of bytes.- Throws:
IOException
-
writeRawBytes
Write part of a byte string.- Throws:
IOException
-
writeTag
Encode and write a tag.- Throws:
IOException
-
computeTagSize
public static int computeTagSize(int fieldNumber) Compute the number of bytes that would be needed to encode a tag. -
writeRawVarint32
Encode and write a varint.value
is treated as unsigned, so it won't be sign-extended if negative.- Throws:
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
Encode and write a varint.- Throws:
IOException
-
computeRawVarint64Size
public static int computeRawVarint64Size(long value) Compute the number of bytes that would be needed to encode a varint. -
writeRawLittleEndian32
Write a little-endian 32-bit integer.- Throws:
IOException
-
writeRawLittleEndian64
Write a little-endian 64-bit integer.- Throws:
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.
-
computeGroupSize(int, com.google.protobuf.MessageLite)
.