Package ghidra.program.model.pcode
Class XmlEncode
java.lang.Object
ghidra.program.model.pcode.XmlEncode
- All Implemented Interfaces:
CachedEncoder,Encoder
An XML based encoder
The underlying transfer encoding is an XML document.
The encoder is initialized with a StringBuilder which will receive the XML document as calls
are made on the encoder.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear any state associated with the encoder The encoder should be ready to write a new document after this call.voidcloseElement(ElementId elemId) End the current element in the encoding The current element must match the given annotation or an exception is thrown.booleanisEmpty()The encoder is considered empty if the writeTo() method would output zero bytesvoidopenElement(ElementId elemId) Begin a new element in the encoding The element will have the given ElementId annotation and becomes the \e current element.toString()voidwriteBool(AttributeId attribId, boolean val) Write an annotated boolean value into the encoding The boolean data is associated with the given AttributeId annotation and the current open element.voidwriteOpcode(AttributeId attribId, int opcode) Write a p-code operation opcode into the encoding, associating it with the given annotation.voidwriteSignedInteger(AttributeId attribId, long val) Write an annotated signed integer value into the encoding The integer is associated with the given AttributeId annotation and the current open element.voidwriteSpace(AttributeId attribId, int index, String name) Write an address space reference into the encoding.voidwriteSpace(AttributeId attribId, AddressSpace spc) Write an address space reference into the encoding The address space is associated with the given AttributeId annotation and the current open element.voidwriteString(AttributeId attribId, String val) Write an annotated string into the encoding The string is associated with the given AttributeId annotation and the current open element.voidwriteStringIndexed(AttributeId attribId, int index, String val) Write an annotated string, using an indexed attribute, into the encoding.voidwriteTo(OutputStream stream) Dump all the accumulated bytes in this encoder to the stream.voidwriteUnsignedInteger(AttributeId attribId, long val) Write an annotated unsigned integer value into the encoding The integer is associated with the given AttributeId annotation and the current open element.
-
Constructor Details
-
XmlEncode
public XmlEncode() -
XmlEncode
public XmlEncode(boolean doFormat)
-
-
Method Details
-
toString
-
clear
public void clear()Description copied from interface:CachedEncoderClear any state associated with the encoder The encoder should be ready to write a new document after this call.- Specified by:
clearin interfaceCachedEncoder
-
openElement
Description copied from interface:EncoderBegin a new element in the encoding The element will have the given ElementId annotation and becomes the \e current element.- Specified by:
openElementin interfaceEncoder- Parameters:
elemId- is the given ElementId annotation- Throws:
IOException- for errors in the underlying stream
-
closeElement
Description copied from interface:EncoderEnd the current element in the encoding The current element must match the given annotation or an exception is thrown.- Specified by:
closeElementin interfaceEncoder- Parameters:
elemId- is the given (expected) annotation for the current element- Throws:
IOException- for errors in the underlying stream
-
writeBool
Description copied from interface:EncoderWrite an annotated boolean value into the encoding The boolean data is associated with the given AttributeId annotation and the current open element.- Specified by:
writeBoolin interfaceEncoder- Parameters:
attribId- is the given AttributeId annotationval- is boolean value to encode- Throws:
IOException- for errors in the underlying stream
-
writeSignedInteger
Description copied from interface:EncoderWrite an annotated signed integer value into the encoding The integer is associated with the given AttributeId annotation and the current open element.- Specified by:
writeSignedIntegerin interfaceEncoder- Parameters:
attribId- is the given AttributeId annotationval- is the signed integer value to encode- Throws:
IOException- for errors in the underlying stream
-
writeUnsignedInteger
Description copied from interface:EncoderWrite an annotated unsigned integer value into the encoding The integer is associated with the given AttributeId annotation and the current open element.- Specified by:
writeUnsignedIntegerin interfaceEncoder- Parameters:
attribId- is the given AttributeId annotationval- is the unsigned integer value to encode- Throws:
IOException- for errors in the underlying stream
-
writeString
Description copied from interface:EncoderWrite an annotated string into the encoding The string is associated with the given AttributeId annotation and the current open element.- Specified by:
writeStringin interfaceEncoder- Parameters:
attribId- is the given AttributeId annotationval- is the string to encode- Throws:
IOException- for errors in the underlying stream
-
writeStringIndexed
Description copied from interface:EncoderWrite an annotated string, using an indexed attribute, into the encoding. Multiple attributes with a shared name can be written to the same element by calling this method multiple times with a different index value. The encoding will use attribute ids up to the base id plus the maximum index passed in. Implementors must be careful to not use other attributes with ids bigger than the base id within the element taking the indexed attribute.- Specified by:
writeStringIndexedin interfaceEncoder- Parameters:
attribId- is the shared AttributeIdindex- is the unique index to associated with the stringval- is the string to encode- Throws:
IOException- for errors in the underlying stream
-
writeSpace
Description copied from interface:EncoderWrite an address space reference into the encoding The address space is associated with the given AttributeId annotation and the current open element.- Specified by:
writeSpacein interfaceEncoder- Parameters:
attribId- is the given AttributeId annotationspc- is the address space to encode- Throws:
IOException- for errors in the underlying stream
-
writeSpace
Description copied from interface:EncoderWrite an address space reference into the encoding. An address space identified by its name and unique index is associated with the given annotation and the current open element.- Specified by:
writeSpacein interfaceEncoder- Parameters:
attribId- is the given annotationindex- is the unique index of the address spacename- is the name of the address space- Throws:
IOException- for errors in the underlying stream
-
writeOpcode
Description copied from interface:EncoderWrite a p-code operation opcode into the encoding, associating it with the given annotation. The opcode is specified based on the constants defined inPcodeOp.- Specified by:
writeOpcodein interfaceEncoder- Parameters:
attribId- is the given annotationopcode- is the opcode constant- Throws:
IOException- for errors in the underlying stream
-
writeTo
Description copied from interface:CachedEncoderDump all the accumulated bytes in this encoder to the stream.- Specified by:
writeToin interfaceCachedEncoder- Parameters:
stream- is the output stream- Throws:
IOException- for errors during the write operation
-
isEmpty
public boolean isEmpty()Description copied from interface:CachedEncoderThe encoder is considered empty if the writeTo() method would output zero bytes- Specified by:
isEmptyin interfaceCachedEncoder- Returns:
- true if there are no bytes in the encoder
-