Package ghidra.features.base.memsearch.bytesequence

# Class AddressableByteSequence

java.lang.Object
ghidra.features.base.memsearch.bytesequence.AddressableByteSequence

All Implemented Interfaces:
  `ByteSequence`

public class AddressableByteSequence extends Object implements ByteSequence
This class provides a `ByteSequence` view into an `AddressableByteSource`. By specifying an address and length, this class provides a view into the byte source as a indexable sequence of bytes. It is mutable and can be reused by setting a new address range for this sequence. This was to avoid constantly allocating large byte arrays.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AddressableByteSequence(AddressableByteSource byteSource, int capacity)`
  Constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Sets this view to an empty byte sequence
  `Address`
  `getAddress(int index)`
  Returns the address of the byte represented by the given index into this buffer.
  `byte`
  `getByte(int index)`
  Returns the byte at the given index.
  `byte[]`
  `getBytes(int index, int size)`
  Returns a byte array containing the bytes from the given range.
  `int`
  `getLength()`
  Returns the length of available bytes.
  `boolean`
  `hasAvailableBytes(int index, int length)`
  A convenience method for checking if this sequence can provide a range of bytes from some offset.
  `void`
  `setRange(AddressRange range)`
  Sets the range of bytes that this object will buffer.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AddressableByteSequence

    public AddressableByteSequence(AddressableByteSource byteSource, int capacity)
    Constructor
    Parameters:
      `byteSource` - the source of the underlying bytes that is a buffer into
      `capacity` - the maximum size range that this object will buffer

- ## Method Details

  - ### clear

    public void clear()
    Sets this view to an empty byte sequence

  - ### setRange

    public void setRange(AddressRange range)
    Sets the range of bytes that this object will buffer. This immediately will read the bytes from the byte source into it's internal byte array buffer.
    Parameters:
      `range` - the range of bytes to buffer

  - ### getAddress

    public Address getAddress(int index)
    Returns the address of the byte represented by the given index into this buffer.
    Parameters:
      `index` - the index into the buffer to get its associated address
    Returns:
      the Address for the given index

  - ### getLength

    public int getLength()
    Description copied from interface: `ByteSequence`
    Returns the length of available bytes.
    Specified by:
      `getLength` in interface `ByteSequence`
    Returns:
      the length of the sequence of bytes

  - ### getByte

    public byte getByte(int index)
    Description copied from interface: `ByteSequence`
    Returns the byte at the given index. The index must between 0 and the extended length.
    Specified by:
      `getByte` in interface `ByteSequence`
    Parameters:
      `index` - the index in the byte sequence to retrieve a byte value
    Returns:
      the byte at the given index

  - ### getBytes

    public byte[] getBytes(int index, int size)
    Description copied from interface: `ByteSequence`
    Returns a byte array containing the bytes from the given range.
    Specified by:
      `getBytes` in interface `ByteSequence`
    Parameters:
      `index` - the start index of the range to get bytes
      `size` - the number of bytes to get
    Returns:
      a byte array containing the bytes from the given range

  - ### hasAvailableBytes

    public boolean hasAvailableBytes(int index, int length)
    Description copied from interface: `ByteSequence`
    A convenience method for checking if this sequence can provide a range of bytes from some offset.
    Specified by:
      `hasAvailableBytes` in interface `ByteSequence`
    Parameters:
      `index` - the index of the start of the range to check for available bytes
      `length` - the length of the range to check for available bytes
    Returns:
      true if bytes are available for the given range