public abstract class CodedOutputStream extends ByteOutput
This class contains two kinds of methods: methods that write specific protocol message
constructs and field types (e.g. writeTag(int, int)
and writeInt32(int, int)
) and methods that
write low-level values (e.g. writeRawVarint32(int)
and writeRawBytes(byte[])
). If you are
writing encoded protocol messages, you should use the former methods, but if you are writing some
other format of your own design, use the latter.
This class is totally unsynchronized.
Modifier and Type | Class and Description |
---|---|
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.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE
The buffer size used in
newInstance(OutputStream) . |
static int |
LITTLE_ENDIAN_32_SIZE
Deprecated.
Use
computeFixed32SizeNoTag(int) instead. |
Modifier and Type | Method and Description |
---|---|
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 unused)
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 unused)
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 unused)
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 unused)
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 unused)
Compute the number of bytes that would be needed to encode a
float field, including
tag. |
static int |
computeGroupSize(int fieldNumber,
MessageLite value)
Deprecated.
groups are deprecated.
|
static int |
computeGroupSizeNoTag(MessageLite value)
Deprecated.
|
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)
Deprecated.
use
computeUInt32SizeNoTag(int) instead. |
static int |
computeRawVarint64Size(long value)
Deprecated.
use
computeUInt64SizeNoTag(long) instead. |
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 unused)
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 unused)
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 |
encodeZigZag32(int n)
Encode a ZigZag-encoded 32-bit value.
|
static long |
encodeZigZag64(long n)
Encode a ZigZag-encoded 64-bit value.
|
abstract void |
flush()
Flushes the stream and forces any buffered bytes to be written.
|
abstract 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.nio.ByteBuffer buffer)
Create a new
CodedOutputStream that writes to the given ByteBuffer . |
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 a
ByteBuffer . Use newInstance(ByteBuffer)
instead. |
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. |
abstract int |
spaceLeft()
If writing to a flat array, return the space left in the array.
|
void |
useDeterministicSerialization()
Configures serialization to be deterministic.
|
abstract void |
write(byte value)
Writes a single byte.
|
abstract void |
write(byte[] value,
int offset,
int length)
Writes a sequence of bytes.
|
abstract void |
write(java.nio.ByteBuffer value)
Writes a sequence of bytes.
|
abstract 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. |
abstract void |
writeByteArray(int fieldNumber,
byte[] value)
Write a
bytes field, including tag, to the stream. |
abstract 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. |
abstract void |
writeByteBuffer(int fieldNumber,
java.nio.ByteBuffer value)
Write a
bytes field, including tag, to the stream. |
abstract void |
writeBytes(int fieldNumber,
ByteString value)
Write a
bytes field, including tag, to the stream. |
abstract 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.
|
abstract void |
writeFixed32(int fieldNumber,
int value)
Write a
fixed32 field, including tag, to the stream. |
abstract void |
writeFixed32NoTag(int value)
Write a
fixed32 field to the stream. |
abstract void |
writeFixed64(int fieldNumber,
long value)
Write a
fixed64 field, including tag, to the stream. |
abstract 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)
Deprecated.
groups are deprecated.
|
void |
writeGroupNoTag(MessageLite value)
Deprecated.
groups are deprecated.
|
abstract void |
writeInt32(int fieldNumber,
int value)
Write an
int32 field, including tag, to the stream. |
abstract 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. |
abstract void |
writeLazy(byte[] value,
int offset,
int length)
Writes a sequence of bytes.
|
abstract void |
writeLazy(java.nio.ByteBuffer value)
Writes a sequence of bytes.
|
abstract void |
writeMessage(int fieldNumber,
MessageLite value)
Write an embedded message field, including tag, to the stream.
|
abstract void |
writeMessageNoTag(MessageLite value)
Write an embedded message field to the stream.
|
abstract 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.
|
abstract void |
writeRawBytes(java.nio.ByteBuffer value)
Write a ByteBuffer.
|
void |
writeRawBytes(ByteString value)
Write a byte string.
|
void |
writeRawLittleEndian32(int value)
Deprecated.
Use
writeFixed32NoTag(int) instead. |
void |
writeRawLittleEndian64(long value)
Deprecated.
Use
writeFixed64NoTag(long) instead. |
abstract void |
writeRawMessageSetExtension(int fieldNumber,
ByteString value)
Write an unparsed MessageSet extension field to the stream.
|
void |
writeRawVarint32(int value)
Deprecated.
use
writeUInt32NoTag(int) instead. |
void |
writeRawVarint64(long value)
Deprecated.
use
writeUInt64NoTag(long) instead. |
void |
writeSFixed32(int fieldNumber,
int value)
Write an
sfixed32 field, including tag, to the stream. |
void |
writeSFixed32NoTag(int value)
Write a
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 a
sfixed64 field to the stream. |
void |
writeSInt32(int fieldNumber,
int value)
Write a
sint32 field, including tag, to the stream. |
void |
writeSInt32NoTag(int value)
Write a
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 a
sint64 field to the stream. |
abstract void |
writeString(int fieldNumber,
java.lang.String value)
Write a
string field, including tag, to the stream. |
abstract void |
writeStringNoTag(java.lang.String value)
Write a
string field to the stream. |
abstract void |
writeTag(int fieldNumber,
int wireType)
Encode and write a tag.
|
abstract void |
writeUInt32(int fieldNumber,
int value)
Write a
uint32 field, including tag, to the stream. |
abstract void |
writeUInt32NoTag(int value)
Write a
uint32 field to the stream. |
abstract void |
writeUInt64(int fieldNumber,
long value)
Write a
uint64 field, including tag, to the stream. |
abstract void |
writeUInt64NoTag(long value)
Write a
uint64 field to the stream. |
@Deprecated public static final int LITTLE_ENDIAN_32_SIZE
computeFixed32SizeNoTag(int)
instead.public static final int DEFAULT_BUFFER_SIZE
newInstance(OutputStream)
.public static CodedOutputStream newInstance(java.io.OutputStream output)
CodedOutputStream
wrapping the given OutputStream
.
NOTE: The provided OutputStream
MUST NOT retain access or modify
the provided byte arrays. Doing so may result in corrupted data, which would be difficult to
debug.
public static CodedOutputStream newInstance(java.io.OutputStream output, int bufferSize)
CodedOutputStream
wrapping the given OutputStream
with a given
buffer size.
NOTE: The provided OutputStream
MUST NOT retain access or modify
the provided byte arrays. Doing so may result in corrupted data, which would be difficult to
debug.
public static CodedOutputStream newInstance(byte[] flatArray)
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)
.public static CodedOutputStream newInstance(byte[] flatArray, int offset, int length)
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)
.public static CodedOutputStream newInstance(java.nio.ByteBuffer buffer)
CodedOutputStream
that writes to the given ByteBuffer
.public void useDeterministicSerialization()
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:
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)
@Deprecated public static CodedOutputStream newInstance(java.nio.ByteBuffer byteBuffer, int unused)
ByteBuffer
. Use newInstance(ByteBuffer)
instead.CodedOutputStream
that writes to the given ByteBuffer
.public abstract void writeTag(int fieldNumber, int wireType) throws java.io.IOException
java.io.IOException
public abstract void writeInt32(int fieldNumber, int value) throws java.io.IOException
int32
field, including tag, to the stream.java.io.IOException
public abstract void writeUInt32(int fieldNumber, int value) throws java.io.IOException
uint32
field, including tag, to the stream.java.io.IOException
public final void writeSInt32(int fieldNumber, int value) throws java.io.IOException
sint32
field, including tag, to the stream.java.io.IOException
public abstract void writeFixed32(int fieldNumber, int value) throws java.io.IOException
fixed32
field, including tag, to the stream.java.io.IOException
public final void writeSFixed32(int fieldNumber, int value) throws java.io.IOException
sfixed32
field, including tag, to the stream.java.io.IOException
public final void writeInt64(int fieldNumber, long value) throws java.io.IOException
int64
field, including tag, to the stream.java.io.IOException
public abstract void writeUInt64(int fieldNumber, long value) throws java.io.IOException
uint64
field, including tag, to the stream.java.io.IOException
public final void writeSInt64(int fieldNumber, long value) throws java.io.IOException
sint64
field, including tag, to the stream.java.io.IOException
public abstract void writeFixed64(int fieldNumber, long value) throws java.io.IOException
fixed64
field, including tag, to the stream.java.io.IOException
public final void writeSFixed64(int fieldNumber, long value) throws java.io.IOException
sfixed64
field, including tag, to the stream.java.io.IOException
public final void writeFloat(int fieldNumber, float value) throws java.io.IOException
float
field, including tag, to the stream.java.io.IOException
public final void writeDouble(int fieldNumber, double value) throws java.io.IOException
double
field, including tag, to the stream.java.io.IOException
public abstract void writeBool(int fieldNumber, boolean value) throws java.io.IOException
bool
field, including tag, to the stream.java.io.IOException
public final void writeEnum(int fieldNumber, int value) throws java.io.IOException
java.io.IOException
public abstract void writeString(int fieldNumber, java.lang.String value) throws java.io.IOException
string
field, including tag, to the stream.java.io.IOException
public abstract void writeBytes(int fieldNumber, ByteString value) throws java.io.IOException
bytes
field, including tag, to the stream.java.io.IOException
public abstract void writeByteArray(int fieldNumber, byte[] value) throws java.io.IOException
bytes
field, including tag, to the stream.java.io.IOException
public abstract void writeByteArray(int fieldNumber, byte[] value, int offset, int length) throws java.io.IOException
bytes
field, including tag, to the stream.java.io.IOException
public abstract void writeByteBuffer(int fieldNumber, java.nio.ByteBuffer value) throws java.io.IOException
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())
.java.io.IOException
public final void writeRawByte(byte value) throws java.io.IOException
java.io.IOException
public final void writeRawByte(int value) throws java.io.IOException
java.io.IOException
public final void writeRawBytes(byte[] value) throws java.io.IOException
java.io.IOException
public final void writeRawBytes(byte[] value, int offset, int length) throws java.io.IOException
java.io.IOException
public final void writeRawBytes(ByteString value) throws java.io.IOException
java.io.IOException
public abstract void writeRawBytes(java.nio.ByteBuffer value) throws java.io.IOException
writeRawBytes(byteBuffer.slice())
.java.io.IOException
public abstract void writeMessage(int fieldNumber, MessageLite value) throws java.io.IOException
java.io.IOException
public abstract void writeMessageSetExtension(int fieldNumber, MessageLite value) throws java.io.IOException
java.io.IOException
public abstract void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws java.io.IOException
java.io.IOException
public abstract void writeInt32NoTag(int value) throws java.io.IOException
int32
field to the stream.java.io.IOException
public abstract void writeUInt32NoTag(int value) throws java.io.IOException
uint32
field to the stream.java.io.IOException
public final void writeSInt32NoTag(int value) throws java.io.IOException
sint32
field to the stream.java.io.IOException
public abstract void writeFixed32NoTag(int value) throws java.io.IOException
fixed32
field to the stream.java.io.IOException
public final void writeSFixed32NoTag(int value) throws java.io.IOException
sfixed32
field to the stream.java.io.IOException
public final void writeInt64NoTag(long value) throws java.io.IOException
int64
field to the stream.java.io.IOException
public abstract void writeUInt64NoTag(long value) throws java.io.IOException
uint64
field to the stream.java.io.IOException
public final void writeSInt64NoTag(long value) throws java.io.IOException
sint64
field to the stream.java.io.IOException
public abstract void writeFixed64NoTag(long value) throws java.io.IOException
fixed64
field to the stream.java.io.IOException
public final void writeSFixed64NoTag(long value) throws java.io.IOException
sfixed64
field to the stream.java.io.IOException
public final void writeFloatNoTag(float value) throws java.io.IOException
float
field to the stream.java.io.IOException
public final void writeDoubleNoTag(double value) throws java.io.IOException
double
field to the stream.java.io.IOException
public final void writeBoolNoTag(boolean value) throws java.io.IOException
bool
field to the stream.java.io.IOException
public final void writeEnumNoTag(int value) throws java.io.IOException
java.io.IOException
public abstract void writeStringNoTag(java.lang.String value) throws java.io.IOException
string
field to the stream.java.io.IOException
public abstract void writeBytesNoTag(ByteString value) throws java.io.IOException
bytes
field to the stream.java.io.IOException
public final void writeByteArrayNoTag(byte[] value) throws java.io.IOException
bytes
field to the stream.java.io.IOException
public abstract void writeMessageNoTag(MessageLite value) throws java.io.IOException
java.io.IOException
@ExperimentalApi public abstract void write(byte value) throws java.io.IOException
ByteOutput
write
in class ByteOutput
value
- the byte to be writtenjava.io.IOException
- thrown if an error occurred while writing@ExperimentalApi public abstract void write(byte[] value, int offset, int length) throws java.io.IOException
ByteOutput
ByteOutput
must copy value
if it will not be
processed prior to the return of this method call, since value
may be reused/altered by
the caller.
NOTE: This method MUST NOT modify the value
. Doing so is a
programming error and will lead to data corruption which will be difficult to debug.
write
in class ByteOutput
value
- the bytes to be writtenoffset
- the offset of the start of the writable rangelength
- the number of bytes to write starting from offset
java.io.IOException
- thrown if an error occurred while writing@ExperimentalApi public abstract void writeLazy(byte[] value, int offset, int length) throws java.io.IOException
ByteOutput
ByteOutput
is free to retain a reference to the value
beyond the scope of this method call (e.g. write later) since it is considered immutable and is
guaranteed not to change by the caller.
NOTE: This method MUST NOT modify the value
. Doing so is a
programming error and will lead to data corruption which will be difficult to debug.
writeLazy
in class ByteOutput
value
- the bytes to be writtenoffset
- the offset of the start of the writable rangelength
- the number of bytes to write starting from offset
java.io.IOException
- thrown if an error occurred while writingpublic abstract void write(java.nio.ByteBuffer value) throws java.io.IOException
ByteOutput
ByteOutput
must copy value
if it will not be
processed prior to the return of this method call, since value
may be reused/altered by
the caller.
NOTE: This method MUST NOT modify the value
. Doing so is a
programming error and will lead to data corruption which will be difficult to debug.
write
in class ByteOutput
value
- the bytes to be written. Upon returning from this call, the position
of
this buffer will be set to the limit
java.io.IOException
- thrown if an error occurred while writing@ExperimentalApi public abstract void writeLazy(java.nio.ByteBuffer value) throws java.io.IOException
ByteOutput
ByteOutput
is free to retain a reference to the value
beyond the scope of this method call (e.g. write later) since it is considered immutable and is
guaranteed not to change by the caller.
NOTE: This method MUST NOT modify the value
. Doing so is a
programming error and will lead to data corruption which will be difficult to debug.
writeLazy
in class ByteOutput
value
- the bytes to be written. Upon returning from this call, the position
of
this buffer will be set to the limit
java.io.IOException
- thrown if an error occurred while writingpublic static int computeInt32Size(int fieldNumber, int value)
int32
field, including
tag.public static int computeUInt32Size(int fieldNumber, int value)
uint32
field, including
tag.public static int computeSInt32Size(int fieldNumber, int value)
sint32
field, including
tag.public static int computeFixed32Size(int fieldNumber, int value)
fixed32
field, including
tag.public static int computeSFixed32Size(int fieldNumber, int value)
sfixed32
field, including
tag.public static int computeInt64Size(int fieldNumber, long value)
int64
field, including
tag.public static int computeUInt64Size(int fieldNumber, long value)
uint64
field, including
tag.public static int computeSInt64Size(int fieldNumber, long value)
sint64
field, including
tag.public static int computeFixed64Size(int fieldNumber, long value)
fixed64
field, including
tag.public static int computeSFixed64Size(int fieldNumber, long value)
sfixed64
field, including
tag.public static int computeFloatSize(int fieldNumber, float value)
float
field, including
tag.public static int computeDoubleSize(int fieldNumber, double value)
double
field, including
tag.public static int computeBoolSize(int fieldNumber, boolean value)
bool
field, including tag.public static int computeEnumSize(int fieldNumber, int value)
public static int computeStringSize(int fieldNumber, java.lang.String value)
string
field, including
tag.public static int computeBytesSize(int fieldNumber, ByteString value)
bytes
field, including
tag.public static int computeByteArraySize(int fieldNumber, byte[] value)
bytes
field, including
tag.public static int computeByteBufferSize(int fieldNumber, java.nio.ByteBuffer value)
bytes
field, including
tag.public static int computeLazyFieldSize(int fieldNumber, LazyFieldLite value)
public static int computeMessageSize(int fieldNumber, MessageLite value)
public static int computeMessageSetExtensionSize(int fieldNumber, MessageLite value)
public static int computeRawMessageSetExtensionSize(int fieldNumber, ByteString value)
public static int computeLazyFieldMessageSetExtensionSize(int fieldNumber, LazyFieldLite value)
public static int computeTagSize(int fieldNumber)
public static int computeInt32SizeNoTag(int value)
int32
field, including
tag.public static int computeUInt32SizeNoTag(int value)
uint32
field.public static int computeSInt32SizeNoTag(int value)
sint32
field.public static int computeFixed32SizeNoTag(int unused)
fixed32
field.public static int computeSFixed32SizeNoTag(int unused)
sfixed32
field.public static int computeInt64SizeNoTag(long value)
int64
field, including
tag.public static int computeUInt64SizeNoTag(long value)
uint64
field, including
tag.public static int computeSInt64SizeNoTag(long value)
sint64
field.public static int computeFixed64SizeNoTag(long unused)
fixed64
field.public static int computeSFixed64SizeNoTag(long unused)
sfixed64
field.public static int computeFloatSizeNoTag(float unused)
float
field, including
tag.public static int computeDoubleSizeNoTag(double unused)
double
field, including
tag.public static int computeBoolSizeNoTag(boolean unused)
bool
field.public static int computeEnumSizeNoTag(int value)
public static int computeStringSizeNoTag(java.lang.String value)
string
field.public static int computeLazyFieldSizeNoTag(LazyFieldLite value)
public static int computeBytesSizeNoTag(ByteString value)
bytes
field.public static int computeByteArraySizeNoTag(byte[] value)
bytes
field.public static int computeByteBufferSizeNoTag(java.nio.ByteBuffer value)
bytes
field.public static int computeMessageSizeNoTag(MessageLite value)
public static int encodeZigZag32(int n)
n
- A signed 32-bit integer.public static long encodeZigZag64(long n)
n
- A signed 64-bit integer.public abstract void flush() throws java.io.IOException
java.io.IOException
public abstract int spaceLeft()
UnsupportedOperationException
.public final void checkNoSpaceLeft()
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.public abstract int getTotalBytesWritten()
@Deprecated public final void writeGroup(int fieldNumber, MessageLite value) throws java.io.IOException
group
field, including tag, to the stream.java.io.IOException
@Deprecated public final void writeGroupNoTag(MessageLite value) throws java.io.IOException
group
field to the stream.java.io.IOException
@Deprecated public static int computeGroupSize(int fieldNumber, MessageLite value)
group
field, including
tag.@Deprecated public static int computeGroupSizeNoTag(MessageLite value)
group
field.@Deprecated public final void writeRawVarint32(int value) throws java.io.IOException
writeUInt32NoTag(int)
instead.value
is treated as unsigned, so it won't be sign-extended
if negative.java.io.IOException
@Deprecated public final void writeRawVarint64(long value) throws java.io.IOException
writeUInt64NoTag(long)
instead.java.io.IOException
@Deprecated public static int computeRawVarint32Size(int value)
computeUInt32SizeNoTag(int)
instead.value
is treated
as unsigned, so it won't be sign-extended if negative.@Deprecated public static int computeRawVarint64Size(long value)
computeUInt64SizeNoTag(long)
instead.@Deprecated public final void writeRawLittleEndian32(int value) throws java.io.IOException
writeFixed32NoTag(int)
instead.java.io.IOException
@Deprecated public final void writeRawLittleEndian64(long value) throws java.io.IOException
writeFixed64NoTag(long)
instead.java.io.IOException
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.