private static class CodedOutputStream.ArrayEncoder extends CodedOutputStream
CodedOutputStream that writes directly to a byte array.CodedOutputStream.OutOfSpaceException| Modifier and Type | Field and Description |
|---|---|
private byte[] |
buffer |
private int |
limit |
private int |
offset |
private int |
position |
DEFAULT_BUFFER_SIZE, LITTLE_ENDIAN_32_SIZE| Constructor and Description |
|---|
ArrayEncoder(byte[] buffer,
int offset,
int length) |
| Modifier and Type | Method and Description |
|---|---|
void |
flush()
Flushes the stream and forces any buffered bytes to be written.
|
int |
getTotalBytesWritten()
Get the total number of bytes successfully written to this stream.
|
int |
spaceLeft()
If writing to a flat array, return the space left in the array.
|
void |
write(byte value)
Writes a single byte.
|
void |
write(byte[] value,
int offset,
int length)
Writes a sequence of bytes.
|
void |
write(java.nio.ByteBuffer value)
Writes a sequence of bytes.
|
void |
writeBool(int fieldNumber,
boolean value)
Write a
bool field, including tag, to the stream. |
void |
writeByteArray(int fieldNumber,
byte[] value)
Write a
bytes field, including tag, to the stream. |
void |
writeByteArray(int fieldNumber,
byte[] value,
int offset,
int length)
Write a
bytes field, including tag, to the stream. |
void |
writeByteArrayNoTag(byte[] value,
int offset,
int length)
Write a
bytes field to the stream. |
void |
writeByteBuffer(int fieldNumber,
java.nio.ByteBuffer value)
Write a
bytes field, including tag, to the stream. |
void |
writeBytes(int fieldNumber,
ByteString value)
Write a
bytes field, including tag, to the stream. |
void |
writeBytesNoTag(ByteString value)
Write a
bytes field to the stream. |
void |
writeFixed32(int fieldNumber,
int value)
Write a
fixed32 field, including tag, to the stream. |
void |
writeFixed32NoTag(int value)
Write a
fixed32 field to the stream. |
void |
writeFixed64(int fieldNumber,
long value)
Write a
fixed64 field, including tag, to the stream. |
void |
writeFixed64NoTag(long value)
Write a
fixed64 field to the stream. |
void |
writeInt32(int fieldNumber,
int value)
Write an
int32 field, including tag, to the stream. |
void |
writeInt32NoTag(int value)
Write an
int32 field to the stream. |
void |
writeLazy(byte[] value,
int offset,
int length)
Writes a sequence of bytes.
|
void |
writeLazy(java.nio.ByteBuffer value)
Writes a sequence of bytes.
|
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 |
writeRawBytes(java.nio.ByteBuffer value)
Write a ByteBuffer.
|
void |
writeRawMessageSetExtension(int fieldNumber,
ByteString value)
Write an unparsed MessageSet extension field to the stream.
|
void |
writeString(int fieldNumber,
java.lang.String value)
Write a
string field, including tag, to the stream. |
void |
writeStringNoTag(java.lang.String value)
Write a
string field to the stream. |
void |
writeTag(int fieldNumber,
int wireType)
Encode and write a tag.
|
void |
writeUInt32(int fieldNumber,
int value)
Write a
uint32 field, including tag, to the stream. |
void |
writeUInt32NoTag(int value)
Write a
uint32 field to the stream. |
void |
writeUInt64(int fieldNumber,
long value)
Write a
uint64 field, including tag, to the stream. |
void |
writeUInt64NoTag(long value)
Write a
uint64 field to the stream. |
checkNoSpaceLeft, computeBoolSize, computeBoolSizeNoTag, computeByteArraySize, computeByteArraySizeNoTag, computeByteBufferSize, computeByteBufferSizeNoTag, computeBytesSize, computeBytesSizeNoTag, computeDoubleSize, computeDoubleSizeNoTag, computeEnumSize, computeEnumSizeNoTag, computeFixed32Size, computeFixed32SizeNoTag, computeFixed64Size, computeFixed64SizeNoTag, computeFloatSize, computeFloatSizeNoTag, computeGroupSize, computeGroupSizeNoTag, computeInt32Size, computeInt32SizeNoTag, computeInt64Size, computeInt64SizeNoTag, computeLazyFieldMessageSetExtensionSize, computeLazyFieldSize, computeLazyFieldSizeNoTag, computeLengthDelimitedFieldSize, computeMessageSetExtensionSize, computeMessageSize, computeMessageSizeNoTag, computePreferredBufferSize, computeRawMessageSetExtensionSize, computeRawVarint32Size, computeRawVarint64Size, computeSFixed32Size, computeSFixed32SizeNoTag, computeSFixed64Size, computeSFixed64SizeNoTag, computeSInt32Size, computeSInt32SizeNoTag, computeSInt64Size, computeSInt64SizeNoTag, computeStringSize, computeStringSizeNoTag, computeTagSize, computeUInt32Size, computeUInt32SizeNoTag, computeUInt64Size, computeUInt64SizeNoTag, encodeZigZag32, encodeZigZag64, inefficientWriteStringNoTag, isSerializationDeterministic, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newSafeInstance, newUnsafeInstance, useDeterministicSerialization, writeBoolNoTag, writeByteArrayNoTag, writeDouble, writeDoubleNoTag, writeEnum, writeEnumNoTag, writeFloat, writeFloatNoTag, writeGroup, writeGroupNoTag, writeInt64, writeInt64NoTag, writeRawByte, writeRawByte, writeRawBytes, writeRawBytes, writeRawBytes, writeRawLittleEndian32, writeRawLittleEndian64, writeRawVarint32, writeRawVarint64, writeSFixed32, writeSFixed32NoTag, writeSFixed64, writeSFixed64NoTag, writeSInt32, writeSInt32NoTag, writeSInt64, writeSInt64NoTagprivate final byte[] buffer
private final int offset
private final int limit
private int position
public final void writeTag(int fieldNumber,
int wireType)
throws java.io.IOException
CodedOutputStreamwriteTag in class CodedOutputStreamjava.io.IOExceptionpublic final void writeInt32(int fieldNumber,
int value)
throws java.io.IOException
CodedOutputStreamint32 field, including tag, to the stream.writeInt32 in class CodedOutputStreamjava.io.IOExceptionpublic final void writeUInt32(int fieldNumber,
int value)
throws java.io.IOException
CodedOutputStreamuint32 field, including tag, to the stream.writeUInt32 in class CodedOutputStreamjava.io.IOExceptionpublic final void writeFixed32(int fieldNumber,
int value)
throws java.io.IOException
CodedOutputStreamfixed32 field, including tag, to the stream.writeFixed32 in class CodedOutputStreamjava.io.IOExceptionpublic final void writeUInt64(int fieldNumber,
long value)
throws java.io.IOException
CodedOutputStreamuint64 field, including tag, to the stream.writeUInt64 in class CodedOutputStreamjava.io.IOExceptionpublic final void writeFixed64(int fieldNumber,
long value)
throws java.io.IOException
CodedOutputStreamfixed64 field, including tag, to the stream.writeFixed64 in class CodedOutputStreamjava.io.IOExceptionpublic final void writeBool(int fieldNumber,
boolean value)
throws java.io.IOException
CodedOutputStreambool field, including tag, to the stream.writeBool in class CodedOutputStreamjava.io.IOExceptionpublic final void writeString(int fieldNumber,
java.lang.String value)
throws java.io.IOException
CodedOutputStreamstring field, including tag, to the stream.writeString in class CodedOutputStreamjava.io.IOExceptionpublic final void writeBytes(int fieldNumber,
ByteString value)
throws java.io.IOException
CodedOutputStreambytes field, including tag, to the stream.writeBytes in class CodedOutputStreamjava.io.IOExceptionpublic final void writeByteArray(int fieldNumber,
byte[] value)
throws java.io.IOException
CodedOutputStreambytes field, including tag, to the stream.writeByteArray in class CodedOutputStreamjava.io.IOExceptionpublic final void writeByteArray(int fieldNumber,
byte[] value,
int offset,
int length)
throws java.io.IOException
CodedOutputStreambytes field, including tag, to the stream.writeByteArray in class CodedOutputStreamjava.io.IOExceptionpublic final void writeByteBuffer(int fieldNumber,
java.nio.ByteBuffer value)
throws java.io.IOException
CodedOutputStreambytes 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()).writeByteBuffer in class CodedOutputStreamjava.io.IOExceptionpublic final void writeBytesNoTag(ByteString value) throws java.io.IOException
CodedOutputStreambytes field to the stream.writeBytesNoTag in class CodedOutputStreamjava.io.IOExceptionpublic final void writeByteArrayNoTag(byte[] value,
int offset,
int length)
throws java.io.IOException
CodedOutputStreambytes field to the stream. Visible for testing.writeByteArrayNoTag in class CodedOutputStreamjava.io.IOExceptionpublic final void writeRawBytes(java.nio.ByteBuffer value)
throws java.io.IOException
CodedOutputStreamwriteRawBytes(byteBuffer.slice()).writeRawBytes in class CodedOutputStreamjava.io.IOExceptionpublic final void writeMessage(int fieldNumber,
MessageLite value)
throws java.io.IOException
CodedOutputStreamwriteMessage in class CodedOutputStreamjava.io.IOExceptionpublic final void writeMessageSetExtension(int fieldNumber,
MessageLite value)
throws java.io.IOException
CodedOutputStreamwriteMessageSetExtension in class CodedOutputStreamjava.io.IOExceptionpublic final void writeRawMessageSetExtension(int fieldNumber,
ByteString value)
throws java.io.IOException
CodedOutputStreamwriteRawMessageSetExtension in class CodedOutputStreamjava.io.IOExceptionpublic final void writeMessageNoTag(MessageLite value) throws java.io.IOException
CodedOutputStreamwriteMessageNoTag in class CodedOutputStreamjava.io.IOExceptionpublic final void write(byte value)
throws java.io.IOException
ByteOutputwrite in class CodedOutputStreamvalue - the byte to be writtenjava.io.IOException - thrown if an error occurred while writingpublic final void writeInt32NoTag(int value)
throws java.io.IOException
CodedOutputStreamint32 field to the stream.writeInt32NoTag in class CodedOutputStreamjava.io.IOExceptionpublic final void writeUInt32NoTag(int value)
throws java.io.IOException
CodedOutputStreamuint32 field to the stream.writeUInt32NoTag in class CodedOutputStreamjava.io.IOExceptionpublic final void writeFixed32NoTag(int value)
throws java.io.IOException
CodedOutputStreamfixed32 field to the stream.writeFixed32NoTag in class CodedOutputStreamjava.io.IOExceptionpublic final void writeUInt64NoTag(long value)
throws java.io.IOException
CodedOutputStreamuint64 field to the stream.writeUInt64NoTag in class CodedOutputStreamjava.io.IOExceptionpublic final void writeFixed64NoTag(long value)
throws java.io.IOException
CodedOutputStreamfixed64 field to the stream.writeFixed64NoTag in class CodedOutputStreamjava.io.IOExceptionpublic final void write(byte[] value,
int offset,
int length)
throws java.io.IOException
ByteOutputByteOutput 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 CodedOutputStreamvalue - the bytes to be writtenoffset - the offset of the start of the writable rangelength - the number of bytes to write starting from offsetjava.io.IOException - thrown if an error occurred while writingpublic final void writeLazy(byte[] value,
int offset,
int length)
throws java.io.IOException
ByteOutputByteOutput 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 CodedOutputStreamvalue - the bytes to be writtenoffset - the offset of the start of the writable rangelength - the number of bytes to write starting from offsetjava.io.IOException - thrown if an error occurred while writingpublic final void write(java.nio.ByteBuffer value)
throws java.io.IOException
ByteOutputByteOutput 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 CodedOutputStreamvalue - the bytes to be written. Upon returning from this call, the position of
this buffer will be set to the limitjava.io.IOException - thrown if an error occurred while writingpublic final void writeLazy(java.nio.ByteBuffer value)
throws java.io.IOException
ByteOutputByteOutput 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 CodedOutputStreamvalue - the bytes to be written. Upon returning from this call, the position of
this buffer will be set to the limitjava.io.IOException - thrown if an error occurred while writingpublic final void writeStringNoTag(java.lang.String value)
throws java.io.IOException
CodedOutputStreamstring field to the stream.writeStringNoTag in class CodedOutputStreamjava.io.IOExceptionpublic void flush()
CodedOutputStreamflush in class CodedOutputStreampublic final int spaceLeft()
CodedOutputStreamUnsupportedOperationException.spaceLeft in class CodedOutputStreampublic final int getTotalBytesWritten()
CodedOutputStreamgetTotalBytesWritten in class CodedOutputStream