- java.lang.Object
-
- de.carne.mcd.instruction.InstructionOpcode
-
- All Implemented Interfaces:
java.lang.Comparable<InstructionOpcode>
public class InstructionOpcode extends java.lang.Object implements java.lang.Comparable<InstructionOpcode>
Immutable byte sequence representing an opcode.
-
-
Field Summary
Fields Modifier and Type Field Description static InstructionOpcodeEMPTYThe empty InstructionOpcode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description bytebyteAt(int n)Gets the nth opcode byte.byte[]bytes()Gets the byte array represented by this opcode.static intcompareTo(byte[] bytes1, int offset1, int length1, byte[] bytes2, int offset2, int length2)intcompareTo(InstructionOpcode o)static InstructionOpcodedecode(byte[] encoded)Decodes a InstructionOpcode previously encoded via encode(int).byte[]encode(int encodedBytes)Encodes this InstructionOpcode for later decoding via decode(byte[]).booleanequals(@Nullable java.lang.Object obj)inthashCode()intlength()Gets the number of bytes represented by this InstructionOpcode instance.static byte[]parse(java.lang.String s)Parses a byte array's string representation as returned by toString() and it's derivates.java.lang.StringtoString()static java.lang.StringtoString(byte[] bytes)Returns the string representation of the given byte array.static java.lang.StringtoString(byte[] bytes, int offset, int length)Returns the string representation of the given byte range.static InstructionOpcodewrap(byte[] bytes)Wraps abytearray into a InstructionOpcode instance (without copying it).static InstructionOpcodewrap(byte[] bytes, int offset, int length)Wraps abytearray into a InstructionOpcode instance (without copying it).
-
-
-
Field Detail
-
EMPTY
public static final InstructionOpcode EMPTY
The empty InstructionOpcode.
-
-
Method Detail
-
wrap
public static InstructionOpcode wrap(byte[] bytes)
Wraps abytearray into a InstructionOpcode instance (without copying it).- Parameters:
bytes- thebytearray backing up the created InstructionOpcode instance.- Returns:
- the InstructionOpcode instance representing the wrapped bytes.
-
wrap
public static InstructionOpcode wrap(byte[] bytes, int offset, int length)
Wraps abytearray into a InstructionOpcode instance (without copying it).- Parameters:
bytes- thebytearray backing up the created InstructionOpcode instance.offset- the offset of the first byte to wrap in thebytearray.length- the number of bytes to wrap in thebytearray.- Returns:
- the InstructionOpcode instance representing the wrapped bytes.
-
decode
public static InstructionOpcode decode(byte[] encoded)
Decodes a InstructionOpcode previously encoded via encode(int).- Parameters:
encoded- the encoded InstructionOpcode as returned by encode(int).- Returns:
- the decoded InstructionOpcode.
-
length
public int length()
Gets the number of bytes represented by this InstructionOpcode instance.- Returns:
- the number of bytes represented by this InstructionOpcode instance.
-
byteAt
public byte byteAt(int n)
Gets the nth opcode byte.- Parameters:
n- the offset of the byte to get.- Returns:
- the nth opcode byte.
-
bytes
public byte[] bytes()
Gets the byte array represented by this opcode.- Returns:
- the byte array represented by this opcode.
-
encode
public byte[] encode(int encodedBytes)
Encodes this InstructionOpcode for later decoding via decode(byte[]).- Parameters:
encodedBytes- the encoding length to use.- Returns:
- the encoded InstructionOpcode.
-
compareTo
public int compareTo(InstructionOpcode o)
- Specified by:
compareToin interfacejava.lang.Comparable<InstructionOpcode>
-
compareTo
public static int compareTo(byte[] bytes1, int offset1, int length1, byte[] bytes2, int offset2, int length2)- Parameters:
bytes1- left hands opcode's bytes.offset1- left hands opcode's offset.length1- left hands opcode's length.bytes2- right hands opcode's bytes.offset2- right hands opcode's offset.length2- right hands opcode's length.- Returns:
- See compareTo(InstructionOpcode)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(@Nullable java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
public static java.lang.String toString(byte[] bytes)
Returns the string representation of the given byte array.- Parameters:
bytes- the bytes to format.- Returns:
- the string representation of the given byte array.
-
toString
public static java.lang.String toString(byte[] bytes, int offset, int length)Returns the string representation of the given byte range.- Parameters:
bytes- the bytes to format.offset- the offset of the first byte to format.length- the number of bytes to format.- Returns:
- the string representation of the given byte range.
-
parse
public static byte[] parse(java.lang.String s)
Parses a byte array's string representation as returned by toString() and it's derivates.- Parameters:
s- the string to parse.- Returns:
- the parsed byte array.
- Throws:
java.lang.NumberFormatException- if the string cannot be parsed.
-
-