Class BufferView

java.lang.Object
org.symbol.sdk.utils.BufferView

public final class BufferView extends Object
BufferView

Buffer view that supports moving / shrinking the visible window over a backing array without copying. Thin wrapper over a little-endian ByteBuffer; the visible window is [position, limit).

  • Constructor Summary

    Constructors
    Constructor
    Description
    BufferView(byte[] buffer)
    Creates buffer view around a buffer.
    Creates a buffer view over a ByteBuffer's remaining bytes.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a ByteBuffer over the visible window (this view is not advanced).
    int
    Returns the length of the visible window.
    byte[]
    peekBytes(int size)
    Copies the first size bytes of the visible window into a fresh array, bounded to the window (a size larger than the remaining bytes throws).
    long
    peekInt(int size, boolean isSigned)
    Reads a little-endian integer of size bytes at the current position without advancing, sign- or zero-extended into a long (an 8-byte unsigned u64 >= 2^63 reads back negative — see Long.toUnsignedString(long)).
    void
    shiftRight(int size)
    Moves view right.
    void
    shrink(int size)
    Shrinks view to specified size.
    Returns an independent, zero-copy view over this view's current window (rebased so reads start at its first byte).
    window(int size)
    Returns a zero-copy view over the first size bytes of the visible window (sharing the backing array; this view is not advanced).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BufferView

      public BufferView(byte[] buffer)
      Creates buffer view around a buffer.
      Parameters:

      buffer - Initial buffer view.

    • BufferView

      public BufferView(ByteBuffer buffer)
      Creates a buffer view over a ByteBuffer's remaining bytes.
      Parameters:

      buffer - Backing buffer; read from its current position, left unmodified.

  • Method Details

    • buffer

      public ByteBuffer buffer()
      BufferView.buffer

      Returns a ByteBuffer over the visible window (this view is not advanced).

      Returns:

      ByteBuffer over the current window.

    • peekBytes

      public byte[] peekBytes(int size)
      BufferView.peekBytes

      Copies the first size bytes of the visible window into a fresh array, bounded to the window (a size larger than the remaining bytes throws). The current position is not advanced (the caller shiftRights by the field's size).

      Parameters:

      size - Number of bytes to copy.

      Returns:

      Copied bytes.

    • length

      public int length()
      BufferView.length

      Returns the length of the visible window.

      Returns:

      Length.

    • shiftRight

      public void shiftRight(int size)
      BufferView.shiftRight

      Moves view right.

      Parameters:

      size - Amount of bytes to shift.

    • window

      public BufferView window(int size)
      BufferView.window

      Returns a zero-copy view over the first size bytes of the visible window (sharing the backing array; this view is not advanced). The window is rebased so reads start at its first byte; copy it out with peekBytes(int).

      Parameters:

      size - Length in bytes.

      Returns:

      View limited to specified size.

    • snapshot

      public BufferView snapshot()
      BufferView.snapshot

      Returns an independent, zero-copy view over this view's current window (rebased so reads start at its first byte). Reads on the returned cursor do not advance this view — used by deserializers to walk a private cursor while the caller advances the original by the object's size().

      Returns:

      Independent view over the same window.

    • shrink

      public void shrink(int size)
      BufferView.shrink

      Shrinks view to specified size.

      Parameters:

      size - New length in bytes.

    • peekInt

      public long peekInt(int size, boolean isSigned)
      BufferView.peekInt

      Reads a little-endian integer of size bytes at the current position without advancing, sign- or zero-extended into a long (an 8-byte unsigned u64 >= 2^63 reads back negative — see Long.toUnsignedString(long)).

      Parameters:

      size - Byte width (1, 2, 4 or 8).

      isSigned - true if the value should be signed (ignored for size == 8, which keeps the raw 64-bit pattern).

      Returns:

      Decoded value.