Package ghidra.program.model.pcode

# Interface PatchEncoder

All Superinterfaces:
  `Encoder`

All Known Implementing Classes:
  `PackedEncode`, `PackedEncodeOverlay`

public interface PatchEncoder extends Encoder
This is an encoder that produces encodings that can be retroactively patched. The contained encoding is expected to be byte based. The user can record a position in the encoding by calling the size() method in the middle of encoding, and then later use the returned offset to call the patchIntegerAttribute() method and modify the encoding at the recorded position.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `patchIntegerAttribute(int pos, AttributeId attribId, long val)`
  Replace an integer attribute for the element at the given position.
  `int`
  `size()`
  The returned value can be used as a position for later modification
  `void`
  `writeSpaceId(AttributeId attribId, long spaceId)`
  Write a given raw spaceid (as returned by AddressSpace.getSpaceID()) as an attribute.

  ### Methods inherited from interface ghidra.program.model.pcode.Encoder

  `clear, closeElement, isEmpty, openElement, writeBool, writeSignedInteger, writeSpace, writeString, writeStringIndexed, writeTo, writeUnsignedInteger`

- ## Method Details

  - ### writeSpaceId

    void writeSpaceId(AttributeId attribId, long spaceId)
    Write a given raw spaceid (as returned by AddressSpace.getSpaceID()) as an attribute. The effect is the same as if writeSpace() was called with the AddressSpace matching the spaceid, i.e. the decoder will read this as just space attribute.
    Parameters:
      `attribId` - is the attribute
      `spaceId` - is the given spaceid

  - ### size

    int size()
    The returned value can be used as a position for later modification
    Returns:
      the number of bytes written to this stream so far

  - ### patchIntegerAttribute

    boolean patchIntegerAttribute(int pos, AttributeId attribId, long val)
    Replace an integer attribute for the element at the given position. The position is assumed to be at an open directive for the element containing the attribute to be patched.
    Parameters:
      `pos` - is the given position
      `attribId` - is the attribute to be patched
      `val` - is the new value to insert
    Returns:
      true if the attribute is successfully patched