Class 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 Detail

      • buffer

        private java.nio.ByteBuffer buffer
      • bufferOffset

        private long bufferOffset
      • limitMinusOne

        private long limitMinusOne
      • pos

        private long pos
    • 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)
      • bytesWrittenToCurrentBuffer

        private int bytesWrittenToCurrentBuffer()
      • spaceLeft

        private int spaceLeft()
      • 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,
                                java.lang.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,
                                 java.lang.Object value)
                          throws java.io.IOException
        Description copied from interface: Writer
        Writes a field of type FieldType.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 type FieldType.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 type FieldType.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 type FieldType.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.
      • writeTag

        void writeTag​(int fieldNumber,
                      int wireType)
        Specified by:
        writeTag 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)
      • 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)
      • 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​(java.nio.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​(java.nio.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