private static final class CodedOutputStream.UnsafeDirectNioEncoder extends CodedOutputStream
CodedOutputStream.OutOfSpaceException
Modifier and Type | Field and Description |
---|---|
private long |
address |
private java.nio.ByteBuffer |
buffer |
private long |
initialPosition |
private long |
limit |
private long |
oneVarintLimit |
private java.nio.ByteBuffer |
originalBuffer |
private long |
position |
DEFAULT_BUFFER_SIZE, LITTLE_ENDIAN_32_SIZE
Constructor and Description |
---|
UnsafeDirectNioEncoder(java.nio.ByteBuffer buffer) |
Modifier and Type | Method and Description |
---|---|
private int |
bufferPos(long pos) |
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.
|
(package private) static boolean |
isSupported() |
private void |
repositionBuffer(long pos) |
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, writeSInt64NoTag
private final java.nio.ByteBuffer originalBuffer
private final java.nio.ByteBuffer buffer
private final long address
private final long initialPosition
private final long limit
private final long oneVarintLimit
private long position
static boolean isSupported()
public void writeTag(int fieldNumber, int wireType) throws java.io.IOException
CodedOutputStream
writeTag
in class CodedOutputStream
java.io.IOException
public void writeInt32(int fieldNumber, int value) throws java.io.IOException
CodedOutputStream
int32
field, including tag, to the stream.writeInt32
in class CodedOutputStream
java.io.IOException
public void writeUInt32(int fieldNumber, int value) throws java.io.IOException
CodedOutputStream
uint32
field, including tag, to the stream.writeUInt32
in class CodedOutputStream
java.io.IOException
public void writeFixed32(int fieldNumber, int value) throws java.io.IOException
CodedOutputStream
fixed32
field, including tag, to the stream.writeFixed32
in class CodedOutputStream
java.io.IOException
public void writeUInt64(int fieldNumber, long value) throws java.io.IOException
CodedOutputStream
uint64
field, including tag, to the stream.writeUInt64
in class CodedOutputStream
java.io.IOException
public void writeFixed64(int fieldNumber, long value) throws java.io.IOException
CodedOutputStream
fixed64
field, including tag, to the stream.writeFixed64
in class CodedOutputStream
java.io.IOException
public void writeBool(int fieldNumber, boolean value) throws java.io.IOException
CodedOutputStream
bool
field, including tag, to the stream.writeBool
in class CodedOutputStream
java.io.IOException
public void writeString(int fieldNumber, java.lang.String value) throws java.io.IOException
CodedOutputStream
string
field, including tag, to the stream.writeString
in class CodedOutputStream
java.io.IOException
public void writeBytes(int fieldNumber, ByteString value) throws java.io.IOException
CodedOutputStream
bytes
field, including tag, to the stream.writeBytes
in class CodedOutputStream
java.io.IOException
public void writeByteArray(int fieldNumber, byte[] value) throws java.io.IOException
CodedOutputStream
bytes
field, including tag, to the stream.writeByteArray
in class CodedOutputStream
java.io.IOException
public void writeByteArray(int fieldNumber, byte[] value, int offset, int length) throws java.io.IOException
CodedOutputStream
bytes
field, including tag, to the stream.writeByteArray
in class CodedOutputStream
java.io.IOException
public void writeByteBuffer(int fieldNumber, java.nio.ByteBuffer value) throws java.io.IOException
CodedOutputStream
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())
.writeByteBuffer
in class CodedOutputStream
java.io.IOException
public void writeMessage(int fieldNumber, MessageLite value) throws java.io.IOException
CodedOutputStream
writeMessage
in class CodedOutputStream
java.io.IOException
public void writeMessageSetExtension(int fieldNumber, MessageLite value) throws java.io.IOException
CodedOutputStream
writeMessageSetExtension
in class CodedOutputStream
java.io.IOException
public void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws java.io.IOException
CodedOutputStream
writeRawMessageSetExtension
in class CodedOutputStream
java.io.IOException
public void writeMessageNoTag(MessageLite value) throws java.io.IOException
CodedOutputStream
writeMessageNoTag
in class CodedOutputStream
java.io.IOException
public void write(byte value) throws java.io.IOException
ByteOutput
write
in class CodedOutputStream
value
- the byte to be writtenjava.io.IOException
- thrown if an error occurred while writingpublic void writeBytesNoTag(ByteString value) throws java.io.IOException
CodedOutputStream
bytes
field to the stream.writeBytesNoTag
in class CodedOutputStream
java.io.IOException
public void writeByteArrayNoTag(byte[] value, int offset, int length) throws java.io.IOException
CodedOutputStream
bytes
field to the stream. Visible for testing.writeByteArrayNoTag
in class CodedOutputStream
java.io.IOException
public void writeRawBytes(java.nio.ByteBuffer value) throws java.io.IOException
CodedOutputStream
writeRawBytes(byteBuffer.slice())
.writeRawBytes
in class CodedOutputStream
java.io.IOException
public void writeInt32NoTag(int value) throws java.io.IOException
CodedOutputStream
int32
field to the stream.writeInt32NoTag
in class CodedOutputStream
java.io.IOException
public void writeUInt32NoTag(int value) throws java.io.IOException
CodedOutputStream
uint32
field to the stream.writeUInt32NoTag
in class CodedOutputStream
java.io.IOException
public void writeFixed32NoTag(int value) throws java.io.IOException
CodedOutputStream
fixed32
field to the stream.writeFixed32NoTag
in class CodedOutputStream
java.io.IOException
public void writeUInt64NoTag(long value) throws java.io.IOException
CodedOutputStream
uint64
field to the stream.writeUInt64NoTag
in class CodedOutputStream
java.io.IOException
public void writeFixed64NoTag(long value) throws java.io.IOException
CodedOutputStream
fixed64
field to the stream.writeFixed64NoTag
in class CodedOutputStream
java.io.IOException
public 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 CodedOutputStream
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 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 CodedOutputStream
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 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 CodedOutputStream
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 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 CodedOutputStream
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 void writeStringNoTag(java.lang.String value) throws java.io.IOException
CodedOutputStream
string
field to the stream.writeStringNoTag
in class CodedOutputStream
java.io.IOException
public void flush()
CodedOutputStream
flush
in class CodedOutputStream
public int spaceLeft()
CodedOutputStream
UnsupportedOperationException
.spaceLeft
in class CodedOutputStream
public int getTotalBytesWritten()
CodedOutputStream
getTotalBytesWritten
in class CodedOutputStream
private void repositionBuffer(long pos)
private int bufferPos(long pos)