Class CodedOutputStream.UnsafeDirectNioEncoder

java.lang.Object
com.google.protobuf.ByteOutput
com.google.protobuf.CodedOutputStream
com.google.protobuf.CodedOutputStream.UnsafeDirectNioEncoder
Enclosing class:
CodedOutputStream

private static final class CodedOutputStream.UnsafeDirectNioEncoder extends CodedOutputStream
A CodedOutputStream that writes directly to a direct ByteBuffer using sun.misc.Unsafe.
  • Field Details

    • originalBuffer

      private final ByteBuffer originalBuffer
    • buffer

      private final ByteBuffer buffer
    • address

      private final long address
    • initialPosition

      private final long initialPosition
    • limit

      private final long limit
    • oneVarintLimit

      private final long oneVarintLimit
    • position

      private long position
  • Constructor Details

    • UnsafeDirectNioEncoder

      UnsafeDirectNioEncoder(ByteBuffer buffer)
  • Method Details

    • isSupported

      static boolean isSupported()
    • writeTag

      public void writeTag(int fieldNumber, int wireType) throws IOException
      Description copied from class: CodedOutputStream
      Encode and write a tag.
      Specified by:
      writeTag in class CodedOutputStream
      Throws:
      IOException
    • writeInt32

      public void writeInt32(int fieldNumber, int value) throws IOException
      Description copied from class: CodedOutputStream
      Write an int32 field, including tag, to the stream.
      Specified by:
      writeInt32 in class CodedOutputStream
      Throws:
      IOException
    • writeUInt32

      public void writeUInt32(int fieldNumber, int value) throws IOException
      Description copied from class: CodedOutputStream
      Write a uint32 field, including tag, to the stream.
      Specified by:
      writeUInt32 in class CodedOutputStream
      Throws:
      IOException
    • writeFixed32

      public void writeFixed32(int fieldNumber, int value) throws IOException
      Description copied from class: CodedOutputStream
      Write a fixed32 field, including tag, to the stream.
      Specified by:
      writeFixed32 in class CodedOutputStream
      Throws:
      IOException
    • writeUInt64

      public void writeUInt64(int fieldNumber, long value) throws IOException
      Description copied from class: CodedOutputStream
      Write a uint64 field, including tag, to the stream.
      Specified by:
      writeUInt64 in class CodedOutputStream
      Throws:
      IOException
    • writeFixed64

      public void writeFixed64(int fieldNumber, long value) throws IOException
      Description copied from class: CodedOutputStream
      Write a fixed64 field, including tag, to the stream.
      Specified by:
      writeFixed64 in class CodedOutputStream
      Throws:
      IOException
    • writeBool

      public void writeBool(int fieldNumber, boolean value) throws IOException
      Description copied from class: CodedOutputStream
      Write a bool field, including tag, to the stream.
      Specified by:
      writeBool in class CodedOutputStream
      Throws:
      IOException
    • writeString

      public void writeString(int fieldNumber, String value) throws IOException
      Description copied from class: CodedOutputStream
      Write a string field, including tag, to the stream.
      Specified by:
      writeString in class CodedOutputStream
      Throws:
      IOException
    • writeBytes

      public void writeBytes(int fieldNumber, ByteString value) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes field, including tag, to the stream.
      Specified by:
      writeBytes in class CodedOutputStream
      Throws:
      IOException
    • writeByteArray

      public void writeByteArray(int fieldNumber, byte[] value) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes field, including tag, to the stream.
      Specified by:
      writeByteArray in class CodedOutputStream
      Throws:
      IOException
    • writeByteArray

      public void writeByteArray(int fieldNumber, byte[] value, int offset, int length) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes field, including tag, to the stream.
      Specified by:
      writeByteArray in class CodedOutputStream
      Throws:
      IOException
    • writeByteBuffer

      public void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException
      Description copied from class: CodedOutputStream
      Write a 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()).
      Specified by:
      writeByteBuffer in class CodedOutputStream
      Throws:
      IOException
    • writeMessage

      public void writeMessage(int fieldNumber, MessageLite value) throws IOException
      Description copied from class: CodedOutputStream
      Write an embedded message field, including tag, to the stream.
      Specified by:
      writeMessage in class CodedOutputStream
      Throws:
      IOException
    • writeMessageSetExtension

      public void writeMessageSetExtension(int fieldNumber, MessageLite value) throws IOException
      Description copied from class: CodedOutputStream
      Write a MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.
      Specified by:
      writeMessageSetExtension in class CodedOutputStream
      Throws:
      IOException
    • writeRawMessageSetExtension

      public void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws IOException
      Description copied from class: CodedOutputStream
      Write an unparsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.
      Specified by:
      writeRawMessageSetExtension in class CodedOutputStream
      Throws:
      IOException
    • writeMessageNoTag

      public void writeMessageNoTag(MessageLite value) throws IOException
      Description copied from class: CodedOutputStream
      Write an embedded message field to the stream.
      Specified by:
      writeMessageNoTag in class CodedOutputStream
      Throws:
      IOException
    • write

      public void write(byte value) throws IOException
      Description copied from class: ByteOutput
      Writes a single byte.
      Specified by:
      write in class CodedOutputStream
      Parameters:
      value - the byte to be written
      Throws:
      IOException - thrown if an error occurred while writing
    • writeBytesNoTag

      public void writeBytesNoTag(ByteString value) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes field to the stream.
      Specified by:
      writeBytesNoTag in class CodedOutputStream
      Throws:
      IOException
    • writeByteArrayNoTag

      public void writeByteArrayNoTag(byte[] value, int offset, int length) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes field to the stream. Visible for testing.
      Specified by:
      writeByteArrayNoTag in class CodedOutputStream
      Throws:
      IOException
    • writeRawBytes

      public void writeRawBytes(ByteBuffer value) throws IOException
      Description copied from class: CodedOutputStream
      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 call writeRawBytes(byteBuffer.slice()).
      Specified by:
      writeRawBytes in class CodedOutputStream
      Throws:
      IOException
    • writeInt32NoTag

      public void writeInt32NoTag(int value) throws IOException
      Description copied from class: CodedOutputStream
      Write an int32 field to the stream.
      Specified by:
      writeInt32NoTag in class CodedOutputStream
      Throws:
      IOException
    • writeUInt32NoTag

      public void writeUInt32NoTag(int value) throws IOException
      Description copied from class: CodedOutputStream
      Write a uint32 field to the stream.
      Specified by:
      writeUInt32NoTag in class CodedOutputStream
      Throws:
      IOException
    • writeFixed32NoTag

      public void writeFixed32NoTag(int value) throws IOException
      Description copied from class: CodedOutputStream
      Write a fixed32 field to the stream.
      Specified by:
      writeFixed32NoTag in class CodedOutputStream
      Throws:
      IOException
    • writeUInt64NoTag

      public void writeUInt64NoTag(long value) throws IOException
      Description copied from class: CodedOutputStream
      Write a uint64 field to the stream.
      Specified by:
      writeUInt64NoTag in class CodedOutputStream
      Throws:
      IOException
    • writeFixed64NoTag

      public void writeFixed64NoTag(long value) throws IOException
      Description copied from class: CodedOutputStream
      Write a fixed64 field to the stream.
      Specified by:
      writeFixed64NoTag in class CodedOutputStream
      Throws:
      IOException
    • write

      public void write(byte[] value, int offset, int length) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The 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.

      Specified by:
      write in class CodedOutputStream
      Parameters:
      value - the bytes to be written
      offset - the offset of the start of the writable range
      length - the number of bytes to write starting from offset
      Throws:
      IOException - thrown if an error occurred while writing
    • writeLazy

      public void writeLazy(byte[] value, int offset, int length) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The 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.

      Specified by:
      writeLazy in class CodedOutputStream
      Parameters:
      value - the bytes to be written
      offset - the offset of the start of the writable range
      length - the number of bytes to write starting from offset
      Throws:
      IOException - thrown if an error occurred while writing
    • write

      public void write(ByteBuffer value) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The 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.

      Specified by:
      write in class CodedOutputStream
      Parameters:
      value - the bytes to be written. Upon returning from this call, the position of this buffer will be set to the limit
      Throws:
      IOException - thrown if an error occurred while writing
    • writeLazy

      public void writeLazy(ByteBuffer value) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The 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.

      Specified by:
      writeLazy in class CodedOutputStream
      Parameters:
      value - the bytes to be written. Upon returning from this call, the position of this buffer will be set to the limit
      Throws:
      IOException - thrown if an error occurred while writing
    • writeStringNoTag

      public void writeStringNoTag(String value) throws IOException
      Description copied from class: CodedOutputStream
      Write a string field to the stream.
      Specified by:
      writeStringNoTag in class CodedOutputStream
      Throws:
      IOException
    • flush

      public void flush()
      Description copied from class: CodedOutputStream
      Flushes the stream and forces any buffered bytes to be written. This does not flush the underlying OutputStream.
      Specified by:
      flush in class CodedOutputStream
    • spaceLeft

      public int spaceLeft()
      Description copied from class: CodedOutputStream
      If writing to a flat array, return the space left in the array. Otherwise, throws UnsupportedOperationException.
      Specified by:
      spaceLeft in class CodedOutputStream
    • getTotalBytesWritten

      public int getTotalBytesWritten()
      Description copied from class: CodedOutputStream
      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.
      Specified by:
      getTotalBytesWritten in class CodedOutputStream
    • repositionBuffer

      private void repositionBuffer(long pos)
    • bufferPos

      private int bufferPos(long pos)