Package com.google.protobuf
Class BinaryWriter.UnsafeDirectWriter
- java.lang.Object
-
- com.google.protobuf.ByteOutput
-
- com.google.protobuf.BinaryWriter
-
- com.google.protobuf.BinaryWriter.UnsafeDirectWriter
-
- All Implemented Interfaces:
Writer
- Enclosing class:
- BinaryWriter
private static final class BinaryWriter.UnsafeDirectWriter extends BinaryWriter
Writer that uses unsafe operations on a targetByteBuffer
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.protobuf.Writer
Writer.FieldOrder
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBuffer
buffer
private long
bufferOffset
private long
limitMinusOne
private long
pos
-
Fields inherited from class com.google.protobuf.BinaryWriter
buffers, DEFAULT_CHUNK_SIZE, totalDoneBytes
-
-
Constructor Summary
Constructors Constructor Description UnsafeDirectWriter(BufferAllocator alloc, int chunkSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private int
bufferPos()
private int
bytesWrittenToCurrentBuffer()
(package private) void
finishCurrentBuffer()
int
getTotalBytesWritten()
Gets the total number of bytes that have been written.private static boolean
isSupported()
Indicates whether the required unsafe operations are supported on this platform.private void
nextBuffer()
private void
nextBuffer(int capacity)
private void
nextBuffer(AllocatedBuffer allocatedBuffer)
(package private) void
requireSpace(int size)
private int
spaceLeft()
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.(package private) void
writeBool(boolean value)
void
writeBool(int fieldNumber, boolean value)
Writes a field of typeFieldType.BOOL
.void
writeBytes(int fieldNumber, ByteString value)
Writes a field of typeFieldType.BYTES
.void
writeEndGroup(int fieldNumber)
Deprecated.(package private) void
writeFixed32(int value)
void
writeFixed32(int fieldNumber, int value)
Writes a field of typeFieldType.FIXED32
.void
writeFixed64(int fieldNumber, long value)
Writes a field of typeFieldType.FIXED64
.(package private) void
writeFixed64(long value)
void
writeGroup(int fieldNumber, java.lang.Object value)
Writes a field of typeFieldType.GROUP
.void
writeGroup(int fieldNumber, java.lang.Object value, Schema schema)
Writes a field of typeFieldType.GROUP
.(package private) void
writeInt32(int value)
void
writeInt32(int fieldNumber, int value)
Writes a field of typeFieldType.INT32
.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, java.lang.Object value)
Writes a field of typeFieldType.MESSAGE
.void
writeMessage(int fieldNumber, java.lang.Object value, Schema schema)
Writes a field of typeFieldType.MESSAGE
.(package private) void
writeSInt32(int value)
void
writeSInt32(int fieldNumber, int value)
Writes a field of typeFieldType.SINT32
.void
writeSInt64(int fieldNumber, long value)
Writes a field of typeFieldType.SINT64
.(package private) void
writeSInt64(long value)
void
writeStartGroup(int fieldNumber)
Deprecated.void
writeString(int fieldNumber, java.lang.String value)
Writes a field of typeFieldType.STRING
.(package private) void
writeString(java.lang.String in)
(package private) void
writeTag(int fieldNumber, int wireType)
void
writeUInt32(int fieldNumber, int value)
Writes a field of typeFieldType.UINT32
.void
writeUInt64(int fieldNumber, long value)
Writes a field of typeFieldType.UINT64
.(package private) void
writeVarint32(int value)
private void
writeVarint32FiveBytes(int value)
private void
writeVarint32FourBytes(int value)
private void
writeVarint32OneByte(int value)
private void
writeVarint32ThreeBytes(int value)
private void
writeVarint32TwoBytes(int value)
(package private) void
writeVarint64(long value)
private void
writeVarint64EightBytes(long value)
private void
writeVarint64FiveBytes(long value)
private void
writeVarint64FourBytes(long value)
private void
writeVarint64NineBytes(long value)
private void
writeVarint64OneByte(long value)
private void
writeVarint64SevenBytes(long value)
private void
writeVarint64SixBytes(long value)
private void
writeVarint64TenBytes(long value)
private void
writeVarint64ThreeBytes(long value)
private void
writeVarint64TwoBytes(long value)
-
Methods inherited from class com.google.protobuf.BinaryWriter
complete, fieldOrder, isUnsafeDirectSupported, isUnsafeHeapSupported, newDirectBuffer, newDirectBuffer, newDirectInstance, newDirectInstance, newHeapBuffer, newHeapBuffer, newHeapInstance, newHeapInstance, newSafeDirectInstance, newSafeHeapInstance, newUnsafeDirectInstance, newUnsafeHeapInstance, writeBoolList, writeBytesList, writeDouble, writeDoubleList, writeEnum, writeEnumList, writeFixed32List, writeFixed64List, writeFloat, writeFloatList, writeGroupList, writeGroupList, writeInt32List, writeInt64, writeInt64List, writeMap, writeMapEntryField, writeMessageList, writeMessageList, writeMessageSetItem, writeSFixed32, writeSFixed32List, writeSFixed64, writeSFixed64List, writeSInt32List, writeSInt64List, writeStringList, writeUInt32List, writeUInt64List
-
-
-
-
Constructor Detail
-
UnsafeDirectWriter
UnsafeDirectWriter(BufferAllocator alloc, int chunkSize)
-
-
Method Detail
-
isSupported
private static boolean isSupported()
Indicates whether the required unsafe operations are supported on this platform.
-
nextBuffer
private void nextBuffer()
-
nextBuffer
private void nextBuffer(int capacity)
-
nextBuffer
private void nextBuffer(AllocatedBuffer allocatedBuffer)
-
getTotalBytesWritten
public int getTotalBytesWritten()
Description copied from class:BinaryWriter
Gets the total number of bytes that have been written. This will not be reset by a call toBinaryWriter.complete()
.- Specified by:
getTotalBytesWritten
in classBinaryWriter
-
bytesWrittenToCurrentBuffer
private int bytesWrittenToCurrentBuffer()
-
spaceLeft
private int spaceLeft()
-
finishCurrentBuffer
void finishCurrentBuffer()
- Specified by:
finishCurrentBuffer
in classBinaryWriter
-
bufferPos
private int bufferPos()
-
writeUInt32
public void writeUInt32(int fieldNumber, int value)
Description copied from interface:Writer
Writes a field of typeFieldType.UINT32
.
-
writeInt32
public void writeInt32(int fieldNumber, int value)
Description copied from interface:Writer
Writes a field of typeFieldType.INT32
.
-
writeSInt32
public void writeSInt32(int fieldNumber, int value)
Description copied from interface:Writer
Writes a field of typeFieldType.SINT32
.
-
writeFixed32
public void writeFixed32(int fieldNumber, int value)
Description copied from interface:Writer
Writes a field of typeFieldType.FIXED32
.
-
writeUInt64
public void writeUInt64(int fieldNumber, long value)
Description copied from interface:Writer
Writes a field of typeFieldType.UINT64
.
-
writeSInt64
public void writeSInt64(int fieldNumber, long value)
Description copied from interface:Writer
Writes a field of typeFieldType.SINT64
.
-
writeFixed64
public void writeFixed64(int fieldNumber, long value)
Description copied from interface:Writer
Writes a field of typeFieldType.FIXED64
.
-
writeBool
public void writeBool(int fieldNumber, boolean value)
Description copied from interface:Writer
Writes a field of typeFieldType.BOOL
.
-
writeString
public void writeString(int fieldNumber, java.lang.String value)
Description copied from interface:Writer
Writes a field of typeFieldType.STRING
.
-
writeBytes
public void writeBytes(int fieldNumber, ByteString value)
Description copied from interface:Writer
Writes a field of typeFieldType.BYTES
.
-
writeMessage
public void writeMessage(int fieldNumber, java.lang.Object value) throws java.io.IOException
Description copied from interface:Writer
Writes a field of typeFieldType.MESSAGE
.- Throws:
java.io.IOException
-
writeMessage
public void writeMessage(int fieldNumber, java.lang.Object value, Schema schema) throws java.io.IOException
Description copied from interface:Writer
Writes a field of typeFieldType.MESSAGE
.- Throws:
java.io.IOException
-
writeGroup
public void writeGroup(int fieldNumber, java.lang.Object value) throws java.io.IOException
Description copied from interface:Writer
Writes a field of typeFieldType.GROUP
.- Throws:
java.io.IOException
-
writeGroup
public void writeGroup(int fieldNumber, java.lang.Object value, Schema schema) throws java.io.IOException
Description copied from interface:Writer
Writes a field of typeFieldType.GROUP
.- Throws:
java.io.IOException
-
writeStartGroup
@Deprecated public void writeStartGroup(int fieldNumber)
Deprecated.Description copied from interface:Writer
Writes a single start group tag.
-
writeEndGroup
@Deprecated public void writeEndGroup(int fieldNumber)
Deprecated.Description copied from interface:Writer
Writes a single end group tag.
-
writeInt32
void writeInt32(int value)
- Specified by:
writeInt32
in classBinaryWriter
-
writeSInt32
void writeSInt32(int value)
- Specified by:
writeSInt32
in classBinaryWriter
-
writeSInt64
void writeSInt64(long value)
- Specified by:
writeSInt64
in classBinaryWriter
-
writeBool
void writeBool(boolean value)
- Specified by:
writeBool
in classBinaryWriter
-
writeTag
void writeTag(int fieldNumber, int wireType)
- Specified by:
writeTag
in classBinaryWriter
-
writeVarint32
void writeVarint32(int value)
- Specified by:
writeVarint32
in classBinaryWriter
-
writeVarint32OneByte
private void writeVarint32OneByte(int value)
-
writeVarint32TwoBytes
private void writeVarint32TwoBytes(int value)
-
writeVarint32ThreeBytes
private void writeVarint32ThreeBytes(int value)
-
writeVarint32FourBytes
private void writeVarint32FourBytes(int value)
-
writeVarint32FiveBytes
private void writeVarint32FiveBytes(int value)
-
writeVarint64
void writeVarint64(long value)
- Specified by:
writeVarint64
in classBinaryWriter
-
writeVarint64OneByte
private void writeVarint64OneByte(long value)
-
writeVarint64TwoBytes
private void writeVarint64TwoBytes(long value)
-
writeVarint64ThreeBytes
private void writeVarint64ThreeBytes(long value)
-
writeVarint64FourBytes
private void writeVarint64FourBytes(long value)
-
writeVarint64FiveBytes
private void writeVarint64FiveBytes(long value)
-
writeVarint64SixBytes
private void writeVarint64SixBytes(long value)
-
writeVarint64SevenBytes
private void writeVarint64SevenBytes(long value)
-
writeVarint64EightBytes
private void writeVarint64EightBytes(long value)
-
writeVarint64NineBytes
private void writeVarint64NineBytes(long value)
-
writeVarint64TenBytes
private void writeVarint64TenBytes(long value)
-
writeFixed32
void writeFixed32(int value)
- Specified by:
writeFixed32
in classBinaryWriter
-
writeFixed64
void writeFixed64(long value)
- Specified by:
writeFixed64
in classBinaryWriter
-
writeString
void writeString(java.lang.String in)
- Specified by:
writeString
in classBinaryWriter
-
write
public void write(byte value)
Description copied from class:ByteOutput
Writes a single byte.- Specified by:
write
in classByteOutput
- Parameters:
value
- the byte to be written
-
write
public void write(byte[] value, int offset, int length)
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
must copyvalue
if it will not be processed prior to the return of this method call, sincevalue
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.- Specified by:
write
in classByteOutput
- Parameters:
value
- the bytes to be writtenoffset
- the offset of the start of the writable rangelength
- the number of bytes to write starting fromoffset
-
writeLazy
public void writeLazy(byte[] value, int offset, int length)
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
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.- Specified by:
writeLazy
in classByteOutput
- Parameters:
value
- the bytes to be writtenoffset
- the offset of the start of the writable rangelength
- the number of bytes to write starting fromoffset
-
write
public void write(java.nio.ByteBuffer value)
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
must copyvalue
if it will not be processed prior to the return of this method call, sincevalue
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.- Specified by:
write
in classByteOutput
- Parameters:
value
- the bytes to be written. Upon returning from this call, theposition
of this buffer will be set to thelimit
-
writeLazy
public void writeLazy(java.nio.ByteBuffer value)
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
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.- Specified by:
writeLazy
in classByteOutput
- Parameters:
value
- the bytes to be written. Upon returning from this call, theposition
of this buffer will be set to thelimit
-
requireSpace
void requireSpace(int size)
- Specified by:
requireSpace
in classBinaryWriter
-
-