Interface ProtonBuffer

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      int capacity()  
      ProtonBuffer capacity​(int newCapacity)
      Adjusts the capacity of this buffer.
      ProtonBuffer clear()
      Reset the read and write offsets to zero and clears the position markers if set previously, this method is not required to reset the data previously written to this buffer.
      int compareTo​(ProtonBuffer buffer)
      Compares the remaining content of the current buffer with the remaining content of the given buffer, which must not be null.
      ProtonBuffer copy()
      Create a deep copy of the readable bytes of this ProtonBuffer, the returned buffer can be modified without affecting the contents or position markers of this instance.
      ProtonBuffer copy​(int index, int length)
      Returns a copy of this buffer's sub-region.
      ProtonBuffer duplicate()
      Create a duplicate of this ProtonBuffer instance that shares the same backing data store and but maintains separate position index values.
      ProtonBuffer ensureWritable​(int amount)
      Ensures that the requested number of bytes is available for write operations in the current buffer, growing the buffer if needed to meet the requested writable capacity.
      byte[] getArray()
      Returns the backing array for this ProtonBuffer instance if there is such an array or throws an exception if this ProtonBuffer implementation has no backing array.
      int getArrayOffset()  
      boolean getBoolean​(int index)
      Gets a boolean from the specified index, this method will not modify the read or write index.
      byte getByte​(int index)
      Gets a byte from the specified index, this method will not modify the read or write index.
      ProtonBuffer getBytes​(int index, byte[] destination)
      Transfers this buffer's data to the specified destination starting at the specified absolute index.
      ProtonBuffer getBytes​(int index, byte[] destination, int offset, int length)
      Transfers this buffer's data to the specified destination starting at the specified absolute index.
      ProtonBuffer getBytes​(int index, java.nio.ByteBuffer destination)
      Transfers this buffer's data to the specified destination starting at the specified absolute index until the destination's position reaches its limit.
      ProtonBuffer getBytes​(int index, ProtonBuffer destination)
      Transfers this buffer's data to the specified destination starting at the specified absolute index until the destination becomes non-writable.
      ProtonBuffer getBytes​(int index, ProtonBuffer destination, int length)
      Transfers this buffer's data to the specified destination starting at the specified absolute index.
      ProtonBuffer getBytes​(int index, ProtonBuffer destination, int offset, int length)
      Transfers this buffer's data to the specified destination starting at the specified absolute index.
      char getChar​(int index)
      Gets a 2-byte char from the specified index, this method will not modify the read or write index.
      double getDouble​(int index)
      Gets a double from the specified index, this method will not modify the read or write index.
      float getFloat​(int index)
      Gets a float from the specified index, this method will not modify the read or write index.
      int getInt​(int index)
      Gets a int from the specified index, this method will not modify the read or write index.
      long getLong​(int index)
      Gets a long from the specified index, this method will not modify the read or write index.
      int getMaxWritableBytes()
      Gets the current maximum number of bytes that can be written to this buffer.
      int getReadableBytes()  
      int getReadIndex()  
      short getShort​(int index)
      Gets a short from the specified index, this method will not modify the read or write index.
      short getUnsignedByte​(int index)
      Gets a unsigned byte from the specified index, this method will not modify the read or write index.
      long getUnsignedInt​(int index)
      Gets a unsigned int from the specified index, this method will not modify the read or write index.
      int getUnsignedShort​(int index)
      Gets a unsigned short from the specified index, this method will not modify the read or write index.
      int getWritableBytes()  
      int getWriteIndex()  
      boolean hasArray()  
      boolean isReadable()  
      boolean isReadable​(int size)
      Check if the given number of bytes can be read from the buffer.
      boolean isWritable()  
      boolean isWritable​(int size)
      Check if the requested number of bytes can be written into this buffer.
      ProtonBuffer markReadIndex()
      Marks the current read index so that it can later be restored by a call to resetReadIndex(), the initial mark value is 0.
      ProtonBuffer markWriteIndex()
      Marks the current write index so that it can later be restored by a call to resetWriteIndex(), the initial mark value is 0.
      int maxCapacity()
      Returns the number of bytes that this buffer is allowed to grow to when write operations exceed the current capacity value.
      boolean readBoolean()
      Reads a boolean value from the buffer and advances the read index by one.
      byte readByte()
      Reads one byte from the buffer and advances the read index by one.
      ProtonBuffer readBytes​(byte[] target)
      Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the value of the length of the destination array.
      ProtonBuffer readBytes​(byte[] target, int length)
      Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the length value passed.
      ProtonBuffer readBytes​(byte[] target, int offset, int length)
      Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the length value passed, the bytes are read into the given buffer starting from the given offset value.
      ProtonBuffer readBytes​(java.nio.ByteBuffer destination)
      Transfers this buffer's data to the specified destination starting at the current readIndex until the destination's position reaches its limit, and increases the readIndex by the number of the transferred bytes.
      ProtonBuffer readBytes​(ProtonBuffer target)
      Reads bytes from this buffer and writes them into the destination ProtonBuffer incrementing the read index by the value of the number of bytes written to the target.
      ProtonBuffer readBytes​(ProtonBuffer target, int length)
      Reads bytes from this buffer and writes them into the destination ProtonBuffer incrementing the read index by the number of bytes written.
      ProtonBuffer readBytes​(ProtonBuffer target, int offset, int length)
      Transfers this buffer's data to the specified destination starting at the current readIndex and increases the readIndex by the number of the transferred bytes (= length).
      double readDouble()
      Reads a double value from the buffer and advances the read index by eight.
      float readFloat()
      Reads a float value from the buffer and advances the read index by four.
      int readInt()
      Reads a integer value from the buffer and advances the read index by four.
      long readLong()
      Reads a long value from the buffer and advances the read index by eight.
      short readShort()
      Reads a short value from the buffer and advances the read index by two.
      ProtonBuffer resetReadIndex()
      Resets the current read index to the previously marked value.
      ProtonBuffer resetWriteIndex()
      Resets the current write index to the previously marked value.
      ProtonBuffer setBoolean​(int index, boolean value)
      Sets the boolean value at the given write index in this buffer's backing data store.
      ProtonBuffer setByte​(int index, int value)
      Sets the byte value at the given write index in this buffer's backing data store.
      ProtonBuffer setBytes​(int index, byte[] source)
      Transfers the specified source array's data to this buffer starting at the specified absolute index.
      ProtonBuffer setBytes​(int index, byte[] source, int offset, int length)
      Transfers the specified source array's data to this buffer starting at the specified absolute index.
      ProtonBuffer setBytes​(int index, java.nio.ByteBuffer source)
      Transfers the specified source buffer's data to this buffer starting at the specified absolute index until the source buffer's position reaches its limit.
      ProtonBuffer setBytes​(int index, ProtonBuffer source)
      Transfers the specified source buffer's data to this buffer starting at the specified absolute index until the source buffer becomes unreadable.
      ProtonBuffer setBytes​(int index, ProtonBuffer source, int length)
      Transfers the specified source buffer's data to this buffer starting at the specified absolute index.
      ProtonBuffer setBytes​(int index, ProtonBuffer source, int offset, int length)
      Transfers the specified source buffer's data to this buffer starting at the specified absolute index.
      ProtonBuffer setChar​(int index, int value)
      Sets the char value at the given write index in this buffer's backing data store.
      ProtonBuffer setDouble​(int index, double value)
      Sets the double value at the given write index in this buffer's backing data store.
      ProtonBuffer setFloat​(int index, float value)
      Sets the float value at the given write index in this buffer's backing data store.
      ProtonBuffer setIndex​(int readIndex, int writeIndex)
      Used to set the read index and the write index in one call.
      ProtonBuffer setInt​(int index, int value)
      Sets the int value at the given write index in this buffer's backing data store.
      ProtonBuffer setLong​(int index, long value)
      Sets the long value at the given write index in this buffer's backing data store.
      ProtonBuffer setReadIndex​(int value)
      Sets the read index for this buffer.
      ProtonBuffer setShort​(int index, int value)
      Sets the short value at the given write index in this buffer's backing data store.
      ProtonBuffer setWriteIndex​(int value)
      Sets the write index for this buffer.
      ProtonBuffer skipBytes​(int length)
      Increases the current readIndex of this buffer by the specified length.
      ProtonBuffer slice()
      Create a new ProtonBuffer whose contents are a subsequence of the contents of this ProtonBuffer.
      ProtonBuffer slice​(int index, int length)
      Create a new ProtonBuffer whose contents are a subsequence of the contents of this ProtonBuffer.
      java.nio.ByteBuffer toByteBuffer()
      Returns a ByteBuffer that represents the readable bytes contained in this buffer.
      java.nio.ByteBuffer toByteBuffer​(int index, int length)
      Returns a ByteBuffer that represents the given span of bytes from the readable portion of this buffer.
      java.lang.String toString​(java.nio.charset.Charset charset)
      Returns a String created from the buffer's underlying bytes using the specified Charset for the newly created String.
      default java.lang.Object unwrap()
      Return the underlying buffer object that backs this ProtonBuffer instance, or null if there is no backing object.
      ProtonBuffer writeBoolean​(boolean value)
      Writes a single boolean to the buffer and advances the write index by one.
      ProtonBuffer writeByte​(int value)
      Writes a single byte to the buffer and advances the write index by one.
      ProtonBuffer writeBytes​(byte[] value)
      Writes the contents of the given byte array into the buffer and advances the write index by the length of the given array.
      ProtonBuffer writeBytes​(byte[] value, int length)
      Writes the contents of the given byte array into the buffer and advances the write index by the length value given.
      ProtonBuffer writeBytes​(byte[] value, int offset, int length)
      Writes the contents of the given byte array into the buffer and advances the write index by the length value given.
      ProtonBuffer writeBytes​(java.nio.ByteBuffer source)
      Transfers the specified source buffer's data to this buffer starting at the current writeIndex until the source buffer's position reaches its limit, and increases the writeIndex by the number of the transferred bytes.
      ProtonBuffer writeBytes​(ProtonBuffer source)
      Transfers the specified source buffer's data to this buffer starting at the current writeIndex until the source buffer becomes unreadable, and increases the writeIndex by the number of the transferred bytes.
      ProtonBuffer writeBytes​(ProtonBuffer source, int length)
      Transfers the specified source buffer's data to this buffer starting at the current writeIndex and increases the writeIndex by the number of the transferred bytes (= length).
      ProtonBuffer writeBytes​(ProtonBuffer source, int offset, int length)
      Transfers the specified source buffer's data to this buffer starting at the current writeIndex and increases the writeIndex by the number of the transferred bytes (= length).
      ProtonBuffer writeDouble​(double value)
      Writes a single double to the buffer and advances the write index by eight.
      ProtonBuffer writeFloat​(float value)
      Writes a single float to the buffer and advances the write index by four.
      ProtonBuffer writeInt​(int value)
      Writes a single integer to the buffer and advances the write index by four.
      ProtonBuffer writeLong​(long value)
      Writes a single long to the buffer and advances the write index by eight.
      ProtonBuffer writeShort​(short value)
      Writes a single short to the buffer and advances the write index by two.
    • Method Detail

      • unwrap

        default java.lang.Object unwrap()
        Return the underlying buffer object that backs this ProtonBuffer instance, or null if there is no backing object. This method should be overridden in buffer abstraction when access to the underlying backing store is needed such as when wrapping pooled resources that need explicit release calls.
        Returns:
        an underlying buffer object or other backing store for this buffer.
      • hasArray

        boolean hasArray()
        Returns:
        true if this buffer has a backing byte array that can be accessed.
      • getArray

        byte[] getArray()
        Returns the backing array for this ProtonBuffer instance if there is such an array or throws an exception if this ProtonBuffer implementation has no backing array.

        Changes to the returned array are visible to other users of this ProtonBuffer.

        Returns:
        the backing byte array for this ProtonBuffer.
        Throws:
        java.lang.UnsupportedOperationException - if this buffer type has no backing array.
      • getArrayOffset

        int getArrayOffset()
        Returns:
        the offset of the first byte in the backing array belonging to this buffer.
        Throws:
        java.lang.UnsupportedOperationException - if this buffer type has no backing array.
      • capacity

        int capacity()
        Returns:
        the number of bytes this buffer can currently contain.
      • capacity

        ProtonBuffer capacity​(int newCapacity)
        Adjusts the capacity of this buffer. If the new capacity is less than the current capacity, the content of this buffer is truncated. If the new capacity is greater than the current capacity, the buffer is appended with unspecified data whose length is new capacity - current capacity.
        Parameters:
        newCapacity - the new maximum capacity value of this buffer.
        Returns:
        this buffer for using in call chaining.
      • maxCapacity

        int maxCapacity()
        Returns the number of bytes that this buffer is allowed to grow to when write operations exceed the current capacity value.
        Returns:
        the number of bytes this buffer is allowed to grow to.
      • ensureWritable

        ProtonBuffer ensureWritable​(int amount)
                             throws java.lang.IndexOutOfBoundsException,
                                    java.lang.IllegalArgumentException
        Ensures that the requested number of bytes is available for write operations in the current buffer, growing the buffer if needed to meet the requested writable capacity. This method will not alter the write offset but may change the value returned from the capacity method if new buffer space is allocated.
        Parameters:
        amount - The number of bytes beyond the current write index needed.
        Returns:
        this buffer for using in call chaining.
        Throws:
        java.lang.IllegalArgumentException - if the amount given is less than zero.
        java.lang.IndexOutOfBoundsException - if the amount given would result in the buffer exceeding the maximum capacity for this buffer.
      • duplicate

        ProtonBuffer duplicate()
        Create a duplicate of this ProtonBuffer instance that shares the same backing data store and but maintains separate position index values. Changes to one buffer are visible in any of its duplicates. This method does not copy the read or write markers to the new buffer instance.
        Returns:
        a new ProtonBuffer instance that shares the backing data as this one.
      • slice

        ProtonBuffer slice()
        Create a new ProtonBuffer whose contents are a subsequence of the contents of this ProtonBuffer.

        The starting point of the new buffer starts at this buffer's current position, the marks and limits of the new buffer will be independent of this buffer however changes to the data backing the buffer will be visible in this buffer.

        Returns:
        a new ProtonBuffer whose contents are a subsequence of this buffer.
      • slice

        ProtonBuffer slice​(int index,
                           int length)
        Create a new ProtonBuffer whose contents are a subsequence of the contents of this ProtonBuffer.

        The starting point of the new buffer starts at given index into this buffer and spans the number of bytes given by the length. Changes to the contents of this buffer or to the produced slice buffer are visible in the other.

        Parameters:
        index - The index in this buffer where the slice should begin.
        length - The number of bytes to make visible to the new buffer from this one.
        Returns:
        a new ProtonBuffer whose contents are a subsequence of this buffer.
      • copy

        ProtonBuffer copy()
        Create a deep copy of the readable bytes of this ProtonBuffer, the returned buffer can be modified without affecting the contents or position markers of this instance.
        Returns:
        a deep copy of this ProtonBuffer instance.
      • copy

        ProtonBuffer copy​(int index,
                          int length)
        Returns a copy of this buffer's sub-region. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method does not modify the value returned from getReadIndex() or getWriteIndex() of this buffer.
        Parameters:
        index - The index in this buffer where the copy should begin
        length - The number of bytes to copy to the new buffer from this one.
        Returns:
        a new ProtonBuffer instance containing the copied bytes.
      • clear

        ProtonBuffer clear()
        Reset the read and write offsets to zero and clears the position markers if set previously, this method is not required to reset the data previously written to this buffer.
        Returns:
        this buffer for using in call chaining.
      • toByteBuffer

        java.nio.ByteBuffer toByteBuffer()
        Returns a ByteBuffer that represents the readable bytes contained in this buffer.

        This method should attempt to return a ByteBuffer that shares the backing data store with this buffer however if that is not possible it is permitted that the returned ByteBuffer contain a copy of the readable bytes of this ProtonBuffer.

        Returns:
        a ByteBuffer that represents the readable bytes of this buffer.
      • toByteBuffer

        java.nio.ByteBuffer toByteBuffer​(int index,
                                         int length)
        Returns a ByteBuffer that represents the given span of bytes from the readable portion of this buffer.

        This method should attempt to return a ByteBuffer that shares the backing data store with this buffer however if that is not possible it is permitted that the returned ByteBuffer contain a copy of the readable bytes of this ProtonBuffer.

        Parameters:
        index - The starting index in this where the ByteBuffer view should begin.
        length - The number of bytes to include in the ByteBuffer view.
        Returns:
        a ByteBuffer that represents the given view of this buffers readable bytes.
      • toString

        java.lang.String toString​(java.nio.charset.Charset charset)
        Returns a String created from the buffer's underlying bytes using the specified Charset for the newly created String.
        Parameters:
        charset - the Charset to use to construct the new string.
        Returns:
        a string created from the buffer's underlying bytes using the given Charset.
      • getReadableBytes

        int getReadableBytes()
        Returns:
        the number of bytes available for reading from this buffer.
      • getWritableBytes

        int getWritableBytes()
        Returns:
        the number of bytes that can be written to this buffer before the limit is hit.
      • getMaxWritableBytes

        int getMaxWritableBytes()
        Gets the current maximum number of bytes that can be written to this buffer. This is the same value that can be computed by subtracting the current write index from the maximum buffer capacity.
        Returns:
        the maximum number of bytes that can be written to this buffer before the limit is hit.
      • getReadIndex

        int getReadIndex()
        Returns:
        the current value of the read index for this buffer.
      • setReadIndex

        ProtonBuffer setReadIndex​(int value)
        Sets the read index for this buffer.
        Parameters:
        value - The index into the buffer where the read index should be positioned.
        Returns:
        this buffer for use in chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the value given is greater than the write index or negative.
      • getWriteIndex

        int getWriteIndex()
        Returns:
        the current value of the write index for this buffer.
      • setWriteIndex

        ProtonBuffer setWriteIndex​(int value)
        Sets the write index for this buffer.
        Parameters:
        value - The index into the buffer where the write index should be positioned.
        Returns:
        this buffer for use in chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the value less than the read index or greater than the capacity.
      • setIndex

        ProtonBuffer setIndex​(int readIndex,
                              int writeIndex)
        Used to set the read index and the write index in one call. This methods allows for an update to the read index and write index to values that could not be set using simple setReadIndex and setWriteIndex call where the values would violate the constraints placed on them by the value of the other index.
        Parameters:
        readIndex - The new read index to assign to this buffer.
        writeIndex - The new write index to assign to this buffer.
        Returns:
        this buffer for use in chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the values violate the basic tenants of readIndex and writeIndex
      • markReadIndex

        ProtonBuffer markReadIndex()
        Marks the current read index so that it can later be restored by a call to resetReadIndex(), the initial mark value is 0.
        Returns:
        this buffer for use in chaining.
      • resetReadIndex

        ProtonBuffer resetReadIndex()
        Resets the current read index to the previously marked value.
        Returns:
        this buffer for use in chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the current write index is less than the marked read index.
      • markWriteIndex

        ProtonBuffer markWriteIndex()
        Marks the current write index so that it can later be restored by a call to resetWriteIndex(), the initial mark value is 0.
        Returns:
        this buffer for use in chaining.
      • resetWriteIndex

        ProtonBuffer resetWriteIndex()
        Resets the current write index to the previously marked value.
        Returns:
        this buffer for use in chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the current read index is greater than the marked write index.
      • isReadable

        boolean isReadable()
        Returns:
        true if the read index is less than the write index.
      • isReadable

        boolean isReadable​(int size)
        Check if the given number of bytes can be read from the buffer.
        Parameters:
        size - the size that is desired in readable bytes
        Returns:
        true if the buffer has at least the given number of readable bytes remaining.
      • compareTo

        int compareTo​(ProtonBuffer buffer)
        Compares the remaining content of the current buffer with the remaining content of the given buffer, which must not be null. Each byte is compared in turn as an unsigned value, returning upon the first difference. If no difference is found before the end of one buffer, the shorter buffer is considered less than the other, or else if the same length then they are considered equal.
        Specified by:
        compareTo in interface java.lang.Comparable<ProtonBuffer>
        Returns:
        a negative, zero, or positive integer when this buffer is less than, equal to, or greater than the given buffer.
        See Also:
        Comparable.compareTo(Object)
      • getBoolean

        boolean getBoolean​(int index)
        Gets a boolean from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getByte

        byte getByte​(int index)
        Gets a byte from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getUnsignedByte

        short getUnsignedByte​(int index)
        Gets a unsigned byte from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getChar

        char getChar​(int index)
        Gets a 2-byte char from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getShort

        short getShort​(int index)
        Gets a short from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getUnsignedShort

        int getUnsignedShort​(int index)
        Gets a unsigned short from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getInt

        int getInt​(int index)
        Gets a int from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getUnsignedInt

        long getUnsignedInt​(int index)
        Gets a unsigned int from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getLong

        long getLong​(int index)
        Gets a long from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getFloat

        float getFloat​(int index)
        Gets a float from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getDouble

        double getDouble​(int index)
        Gets a double from the specified index, this method will not modify the read or write index.
        Parameters:
        index - The index into the buffer where the value should be read.
        Returns:
        the value read from the given index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or past the current buffer capacity.
      • getBytes

        ProtonBuffer getBytes​(int index,
                              ProtonBuffer destination)
        Transfers this buffer's data to the specified destination starting at the specified absolute index until the destination becomes non-writable. This method is basically same with getBytes(int, ProtonBuffer, int, int), except that this method increases the writeIndex of the destination by the number of the transferred bytes while getBytes(int, ProtonBuffer, int, int) does not. This method does not modify readIndex or writeIndex of the source buffer (i.e. this).
        Parameters:
        index - The index into the buffer where the value should be read.
        destination - the destination buffer for the bytes to be read
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0 or if index + dst.writableBytes is greater than this.capacity
      • getBytes

        ProtonBuffer getBytes​(int index,
                              ProtonBuffer destination,
                              int length)
        Transfers this buffer's data to the specified destination starting at the specified absolute index. This method is basically same with getBytes(int, ProtonBuffer, int, int), except that this method increases the writeIndex of the destination by the number of the transferred bytes while getBytes(int, ProtonBuffer, int, int) does not. This method does not modify readIndex or writeIndex of the source buffer (i.e. this).
        Parameters:
        index - the index in the buffer to start the read from
        destination - the destination buffer for the bytes to be read
        length - the number of bytes to transfer
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0, if index + length is greater than this.capacity, or if length is greater than dst.writableBytes
      • getBytes

        ProtonBuffer getBytes​(int index,
                              ProtonBuffer destination,
                              int offset,
                              int length)
        Transfers this buffer's data to the specified destination starting at the specified absolute index. This method does not modify readIndex or writeIndex of both the source (i.e. this) and the destination.
        Parameters:
        index - The index into the buffer where the value should be read.
        destination - The buffer where the bytes read will be written to
        offset - The offset into the destination where the write starts
        length - The number of bytes to transfer
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0, if the specified dstIndex is less than 0, if index + length is greater than this.capacity, or if dstIndex + length is greater than dst.capacity
      • getBytes

        ProtonBuffer getBytes​(int index,
                              byte[] destination)
        Transfers this buffer's data to the specified destination starting at the specified absolute index. This method does not modify readIndex or writeIndex of this buffer
        Parameters:
        index - The index into the buffer where the value should be read.
        destination - The buffer where the bytes read will be written to
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0 or if index + dst.length is greater than this.capacity
      • getBytes

        ProtonBuffer getBytes​(int index,
                              byte[] destination,
                              int offset,
                              int length)
        Transfers this buffer's data to the specified destination starting at the specified absolute index. This method does not modify #getReadIndex() or #getWriteIndex() of this buffer.
        Parameters:
        index - The index into the buffer where the value should be read.
        destination - The buffer where the bytes read will be written to
        offset - the offset into the destination to begin writing the bytes.
        length - the number of bytes to transfer from this buffer to the target buffer.
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0, if the specified offset is less than 0, if index + length is greater than this.capacity, or if offset + length is greater than target.length
      • getBytes

        ProtonBuffer getBytes​(int index,
                              java.nio.ByteBuffer destination)
        Transfers this buffer's data to the specified destination starting at the specified absolute index until the destination's position reaches its limit. This method does not modify #getReadIndex() or #getWriteIndex() of this buffer while the destination's position will be increased.
        Parameters:
        index - The index into the buffer where the value should be read.
        destination - The buffer where the bytes read will be written to
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0 or if index + destination.remaining() is greater than #capacity()
      • setByte

        ProtonBuffer setByte​(int index,
                             int value)
        Sets the byte value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or the write would exceed capacity.
      • setBoolean

        ProtonBuffer setBoolean​(int index,
                                boolean value)
        Sets the boolean value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or the write would exceed capacity.
      • setChar

        ProtonBuffer setChar​(int index,
                             int value)
        Sets the char value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or the write would exceed capacity.
      • setShort

        ProtonBuffer setShort​(int index,
                              int value)
        Sets the short value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or the write would exceed capacity.
      • setInt

        ProtonBuffer setInt​(int index,
                            int value)
        Sets the int value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or the write would exceed capacity.
      • setLong

        ProtonBuffer setLong​(int index,
                             long value)
        Sets the long value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or the write would exceed capacity.
      • setFloat

        ProtonBuffer setFloat​(int index,
                              float value)
        Sets the float value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or the write would exceed capacity.
      • setDouble

        ProtonBuffer setDouble​(int index,
                               double value)
        Sets the double value at the given write index in this buffer's backing data store.
        Parameters:
        index - The index to start the write from.
        value - The value to write at the given index.
        Returns:
        a reference to this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or the write would exceed capacity.
      • setBytes

        ProtonBuffer setBytes​(int index,
                              ProtonBuffer source)
        Transfers the specified source buffer's data to this buffer starting at the specified absolute index until the source buffer becomes unreadable. This method is basically same with setBytes(int, ProtonBuffer, int, int), except that this method increases the readIndex of the source buffer by the number of the transferred bytes while setBytes(int, ProtonBuffer, int, int) does not. This method does not modify readIndex or writeIndex of the source buffer (i.e. this).
        Parameters:
        index - The index in this buffer where the write operation starts.
        source - The source buffer from which the bytes are read.
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0 or if index + source.readableBytes is greater than this.capacity
      • setBytes

        ProtonBuffer setBytes​(int index,
                              ProtonBuffer source,
                              int length)
        Transfers the specified source buffer's data to this buffer starting at the specified absolute index. This method is basically same with setBytes(int, ProtonBuffer, int, int), except that this method increases the readIndex of the source buffer by the number of the transferred bytes while setBytes(int, ProtonBuffer, int, int) does not. This method does not modify readIndex or writeIndex of the source buffer (i.e. this).
        Parameters:
        index - The index in this buffer where the write operation starts.
        source - The source buffer from which the bytes are read.
        length - The number of bytes to transfer
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0, if index + length is greater than this.capacity, or if length is greater than source.readableBytes
      • setBytes

        ProtonBuffer setBytes​(int index,
                              ProtonBuffer source,
                              int offset,
                              int length)
        Transfers the specified source buffer's data to this buffer starting at the specified absolute index. This method does not modify readIndex or writeIndex of both the source (i.e. this) and the destination.
        Parameters:
        index - The index in this buffer where the write operation starts.
        source - The source buffer from which the bytes are read.
        offset - The offset into the source where the set begins.
        length - The number of bytes to transfer
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0, if the specified sourceIndex is less than 0, if index + length is greater than this.capacity, or if sourceIndex + length is greater than source.capacity
      • setBytes

        ProtonBuffer setBytes​(int index,
                              byte[] source)
        Transfers the specified source array's data to this buffer starting at the specified absolute index. This method does not modify readIndex or writeIndex of this buffer.
        Parameters:
        index - The index in this buffer where the write operation starts.
        source - The source buffer from which the bytes are read.
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0 or if index + source.length is greater than this.capacity
      • setBytes

        ProtonBuffer setBytes​(int index,
                              byte[] source,
                              int offset,
                              int length)
        Transfers the specified source array's data to this buffer starting at the specified absolute index. This method does not modify readIndex or writeIndex of this buffer.
        Parameters:
        index - The index in this buffer where the write operation starts.
        source - The source buffer from which the bytes are read.
        offset - The offset into the source where the set begins.
        length - The number of bytes to transfer
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0, if the specified offset is less than 0, if index + length is greater than this.capacity, or if offset + length is greater than source.length
      • setBytes

        ProtonBuffer setBytes​(int index,
                              java.nio.ByteBuffer source)
        Transfers the specified source buffer's data to this buffer starting at the specified absolute index until the source buffer's position reaches its limit. This method does not modify readIndex or writeIndex of this buffer.
        Parameters:
        index - The index in this buffer where the write operation starts.
        source - The source buffer from which the bytes are read.
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is less than 0 or if index + source.remaining() is greater than this.capacity
      • skipBytes

        ProtonBuffer skipBytes​(int length)
        Increases the current readIndex of this buffer by the specified length.
        Parameters:
        length - the number of bytes in this buffer to skip.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if length is greater than this.readableBytes
      • readByte

        byte readByte()
        Reads one byte from the buffer and advances the read index by one.
        Returns:
        a single byte from the ProtonBuffer.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no readable bytes left in the buffer.
      • readBytes

        ProtonBuffer readBytes​(byte[] target)
        Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the value of the length of the destination array.
        Parameters:
        target - The byte array to write into.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the target array is larger than the readable bytes.
      • readBytes

        ProtonBuffer readBytes​(byte[] target,
                               int length)
        Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the length value passed.
        Parameters:
        target - The byte array to write into.
        length - The number of bytes to read into the given array.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the length is larger than the readable bytes, or length is greater than the length of the target array, or length is negative.
      • readBytes

        ProtonBuffer readBytes​(byte[] target,
                               int offset,
                               int length)
        Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the length value passed, the bytes are read into the given buffer starting from the given offset value.
        Parameters:
        target - The byte array to write into.
        offset - The offset into the given array where bytes are written.
        length - The number of bytes to read into the given array.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the offset is negative, or if the length is greater than the current readable bytes or if the offset + length is great than the size of the target.
      • readBytes

        ProtonBuffer readBytes​(ProtonBuffer target)
        Reads bytes from this buffer and writes them into the destination ProtonBuffer incrementing the read index by the value of the number of bytes written to the target. The number of bytes written will be the equal to the writable bytes of the target buffer. The write index of the target buffer will be incremented by the number of bytes written into it.
        Parameters:
        target - The ProtonBuffer to write into.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IllegalArgumentException - if the target buffer is this buffer.
        java.lang.IndexOutOfBoundsException - if the target buffer has more writable bytes than this buffer has readable bytes.
      • readBytes

        ProtonBuffer readBytes​(ProtonBuffer target,
                               int length)
        Reads bytes from this buffer and writes them into the destination ProtonBuffer incrementing the read index by the number of bytes written. The write index of the target buffer will be incremented by the number of bytes written into it.
        Parameters:
        target - The ProtonBuffer to write into.
        length - The number of bytes to read into the given buffer.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the length value is greater than the readable bytes of this buffer or is greater than the writable bytes of the target buffer..
      • readBytes

        ProtonBuffer readBytes​(ProtonBuffer target,
                               int offset,
                               int length)
        Transfers this buffer's data to the specified destination starting at the current readIndex and increases the readIndex by the number of the transferred bytes (= length). This method does not modify the write index of the target buffer.
        Parameters:
        target - The ProtonBuffer to write into.
        offset - The offset into the given buffer where bytes are written.
        length - The number of bytes to read into the given buffer.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the offset is negative, or if the length is greater than the current readable bytes or if the offset + length is great than the size of the target.
      • readBytes

        ProtonBuffer readBytes​(java.nio.ByteBuffer destination)
        Transfers this buffer's data to the specified destination starting at the current readIndex until the destination's position reaches its limit, and increases the readIndex by the number of the transferred bytes.
        Parameters:
        destination - The target ByteBuffer to write into.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if the destination does not have enough capacity.
      • readBoolean

        boolean readBoolean()
        Reads a boolean value from the buffer and advances the read index by one.
        Returns:
        boolean value read from the buffer.
        Throws:
        java.lang.IndexOutOfBoundsException - if a value cannot be read from the buffer.
      • readShort

        short readShort()
        Reads a short value from the buffer and advances the read index by two.
        Returns:
        short value read from the buffer.
        Throws:
        java.lang.IndexOutOfBoundsException - if a value cannot be read from the buffer.
      • readInt

        int readInt()
        Reads a integer value from the buffer and advances the read index by four.
        Returns:
        integer value read from the buffer.
        Throws:
        java.lang.IndexOutOfBoundsException - if a value cannot be read from the buffer.
      • readLong

        long readLong()
        Reads a long value from the buffer and advances the read index by eight.
        Returns:
        long value read from the buffer.
        Throws:
        java.lang.IndexOutOfBoundsException - if a value cannot be read from the buffer.
      • readFloat

        float readFloat()
        Reads a float value from the buffer and advances the read index by four.
        Returns:
        float value read from the buffer.
        Throws:
        java.lang.IndexOutOfBoundsException - if a value cannot be read from the buffer.
      • readDouble

        double readDouble()
        Reads a double value from the buffer and advances the read index by eight.
        Returns:
        double value read from the buffer.
        Throws:
        java.lang.IndexOutOfBoundsException - if a value cannot be read from the buffer.
      • isWritable

        boolean isWritable()
        Returns:
        true if the buffer has bytes remaining between the write index and the capacity.
      • isWritable

        boolean isWritable​(int size)
        Check if the requested number of bytes can be written into this buffer.
        Parameters:
        size - The number writable bytes that is being checked in this buffer.
        Returns:
        true if the buffer has space left for the given number of bytes to be written.
      • writeByte

        ProtonBuffer writeByte​(int value)
        Writes a single byte to the buffer and advances the write index by one.
        Parameters:
        value - The byte to write into the buffer.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no room in the buffer for this write operation.
      • writeBytes

        ProtonBuffer writeBytes​(byte[] value)
        Writes the contents of the given byte array into the buffer and advances the write index by the length of the given array.
        Parameters:
        value - The byte array to write into the buffer.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no room in the buffer for this write operation.
      • writeBytes

        ProtonBuffer writeBytes​(byte[] value,
                                int length)
        Writes the contents of the given byte array into the buffer and advances the write index by the length value given.
        Parameters:
        value - The byte array to write into the buffer.
        length - The number of bytes to write from the given array into this buffer
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no room in the buffer for this write operation.
      • writeBytes

        ProtonBuffer writeBytes​(byte[] value,
                                int offset,
                                int length)
        Writes the contents of the given byte array into the buffer and advances the write index by the length value given. The bytes written into this buffer are read starting at the given offset into the passed in byte array.
        Parameters:
        value - The byte array to write into the buffer.
        offset - The offset into the given array to start reading from.
        length - The number of bytes to write from the given array into this buffer
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no room in the buffer for this write operation.
      • writeBytes

        ProtonBuffer writeBytes​(ProtonBuffer source)
        Transfers the specified source buffer's data to this buffer starting at the current writeIndex until the source buffer becomes unreadable, and increases the writeIndex by the number of the transferred bytes. This method is basically same with writeBytes(ProtonBuffer, int, int), except that this method increases the readIndex of the source buffer by the number of the transferred bytes while writeBytes(ProtonBuffer, int, int) does not.
        Parameters:
        source - The source buffer from which the bytes are read.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if source.readableBytes is greater than this.writableBytes
      • writeBytes

        ProtonBuffer writeBytes​(ProtonBuffer source,
                                int length)
        Transfers the specified source buffer's data to this buffer starting at the current writeIndex and increases the writeIndex by the number of the transferred bytes (= length). This method is basically same with writeBytes(ProtonBuffer, int, int), except that this method increases the readIndex of the source buffer by the number of the transferred bytes (= length) while writeBytes(ProtonBuffer, int, int) does not.
        Parameters:
        source - The source buffer from which the bytes are read.
        length - The number of bytes to transfer
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if length is greater than this.writableBytes or if length is greater then source.readableBytes
      • writeBytes

        ProtonBuffer writeBytes​(ProtonBuffer source,
                                int offset,
                                int length)
        Transfers the specified source buffer's data to this buffer starting at the current writeIndex and increases the writeIndex by the number of the transferred bytes (= length). This method does not modify the read index of the source buffer.
        Parameters:
        source - The source buffer from which the bytes are read.
        offset - The offset in the source buffer to start writing into this buffer.
        length - The number of bytes to transfer
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified offset is less than 0, if offset + length is greater than source.capacity, or if length is greater than this.writableBytes
      • writeBytes

        ProtonBuffer writeBytes​(java.nio.ByteBuffer source)
        Transfers the specified source buffer's data to this buffer starting at the current writeIndex until the source buffer's position reaches its limit, and increases the writeIndex by the number of the transferred bytes.
        Parameters:
        source - The source buffer from which the bytes are read.
        Returns:
        this buffer for chaining
        Throws:
        java.lang.IndexOutOfBoundsException - if source.remaining() is greater than this.writableBytes
      • writeBoolean

        ProtonBuffer writeBoolean​(boolean value)
        Writes a single boolean to the buffer and advances the write index by one.
        Parameters:
        value - The boolean to write into the buffer.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no room in the buffer for this write operation.
      • writeShort

        ProtonBuffer writeShort​(short value)
        Writes a single short to the buffer and advances the write index by two.
        Parameters:
        value - The short to write into the buffer.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no room in the buffer for this write operation.
      • writeInt

        ProtonBuffer writeInt​(int value)
        Writes a single integer to the buffer and advances the write index by four.
        Parameters:
        value - The integer to write into the buffer.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no room in the buffer for this write operation.
      • writeLong

        ProtonBuffer writeLong​(long value)
        Writes a single long to the buffer and advances the write index by eight.
        Parameters:
        value - The long to write into the buffer.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no room in the buffer for this write operation.
      • writeFloat

        ProtonBuffer writeFloat​(float value)
        Writes a single float to the buffer and advances the write index by four.
        Parameters:
        value - The float to write into the buffer.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no room in the buffer for this write operation.
      • writeDouble

        ProtonBuffer writeDouble​(double value)
        Writes a single double to the buffer and advances the write index by eight.
        Parameters:
        value - The double to write into the buffer.
        Returns:
        this ProtonBuffer for chaining.
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no room in the buffer for this write operation.