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 target ByteBuffer.
  • Field Details

    • buffer

      private ByteBuffer buffer
    • bufferOffset

      private long bufferOffset
    • limitMinusOne

      private long limitMinusOne
    • pos

      private long pos
  • Constructor Details

    • UnsafeDirectWriter

      UnsafeDirectWriter(BufferAllocator alloc, int chunkSize)
  • Method Details

    • 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 to BinaryWriter.complete().
      Specified by:
      getTotalBytesWritten in class BinaryWriter
    • bytesWrittenToCurrentBuffer

      private int bytesWrittenToCurrentBuffer()
    • spaceLeft

      private int spaceLeft()
    • finishCurrentBuffer

      void finishCurrentBuffer()
      Specified by:
      finishCurrentBuffer in class BinaryWriter
    • bufferPos

      private int bufferPos()
    • writeUInt32

      public void writeUInt32(int fieldNumber, int value)
      Description copied from interface: Writer
      Writes a field of type FieldType.UINT32.
    • writeInt32

      public void writeInt32(int fieldNumber, int value)
      Description copied from interface: Writer
      Writes a field of type FieldType.INT32.
    • writeSInt32

      public void writeSInt32(int fieldNumber, int value)
      Description copied from interface: Writer
      Writes a field of type FieldType.SINT32.
    • writeFixed32

      public void writeFixed32(int fieldNumber, int value)
      Description copied from interface: Writer
      Writes a field of type FieldType.FIXED32.
    • writeUInt64

      public void writeUInt64(int fieldNumber, long value)
      Description copied from interface: Writer
      Writes a field of type FieldType.UINT64.
    • writeSInt64

      public void writeSInt64(int fieldNumber, long value)
      Description copied from interface: Writer
      Writes a field of type FieldType.SINT64.
    • writeFixed64

      public void writeFixed64(int fieldNumber, long value)
      Description copied from interface: Writer
      Writes a field of type FieldType.FIXED64.
    • writeBool

      public void writeBool(int fieldNumber, boolean value)
      Description copied from interface: Writer
      Writes a field of type FieldType.BOOL.
    • writeString

      public void writeString(int fieldNumber, String value)
      Description copied from interface: Writer
      Writes a field of type FieldType.STRING.
    • writeBytes

      public void writeBytes(int fieldNumber, ByteString value)
      Description copied from interface: Writer
      Writes a field of type FieldType.BYTES.
    • writeMessage

      public void writeMessage(int fieldNumber, Object value) throws IOException
      Description copied from interface: Writer
      Writes a field of type FieldType.MESSAGE.
      Throws:
      IOException
    • writeMessage

      public void writeMessage(int fieldNumber, Object value, Schema schema) throws IOException
      Description copied from interface: Writer
      Writes a field of type FieldType.MESSAGE.
      Throws:
      IOException
    • writeGroup

      public void writeGroup(int fieldNumber, Object value) throws IOException
      Description copied from interface: Writer
      Writes a field of type FieldType.GROUP.
      Throws:
      IOException
    • writeGroup

      public void writeGroup(int fieldNumber, Object value, Schema schema) throws IOException
      Description copied from interface: Writer
      Writes a field of type FieldType.GROUP.
      Throws:
      IOException
    • writeStartGroup

      public void writeStartGroup(int fieldNumber)
      Description copied from interface: Writer
      Writes a single start group tag.
    • writeEndGroup

      public void writeEndGroup(int fieldNumber)
      Description copied from interface: Writer
      Writes a single end group tag.
    • writeInt32

      void writeInt32(int value)
      Specified by:
      writeInt32 in class BinaryWriter
    • writeSInt32

      void writeSInt32(int value)
      Specified by:
      writeSInt32 in class BinaryWriter
    • writeSInt64

      void writeSInt64(long value)
      Specified by:
      writeSInt64 in class BinaryWriter
    • writeBool

      void writeBool(boolean value)
      Specified by:
      writeBool in class BinaryWriter
    • writeTag

      void writeTag(int fieldNumber, int wireType)
      Specified by:
      writeTag in class BinaryWriter
    • writeVarint32

      void writeVarint32(int value)
      Specified by:
      writeVarint32 in class BinaryWriter
    • 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 class BinaryWriter
    • 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 class BinaryWriter
    • writeFixed64

      void writeFixed64(long value)
      Specified by:
      writeFixed64 in class BinaryWriter
    • writeString

      void writeString(String in)
      Specified by:
      writeString in class BinaryWriter
    • write

      public void write(byte value)
      Description copied from class: ByteOutput
      Writes a single byte.
      Specified by:
      write in class ByteOutput
      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. 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 ByteOutput
      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
    • writeLazy

      public void writeLazy(byte[] value, int offset, int length)
      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 ByteOutput
      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
    • write

      public void write(ByteBuffer value)
      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 ByteOutput
      Parameters:
      value - the bytes to be written. Upon returning from this call, the position of this buffer will be set to the limit
    • writeLazy

      public void writeLazy(ByteBuffer value)
      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 ByteOutput
      Parameters:
      value - the bytes to be written. Upon returning from this call, the position of this buffer will be set to the limit
    • requireSpace

      void requireSpace(int size)
      Specified by:
      requireSpace in class BinaryWriter