public abstract class NumberType extends Object implements MagicMatcher
MagicMatcher.MutableOffset
Modifier and Type | Field and Description |
---|---|
protected EndianConverter |
endianConverter |
Constructor and Description |
---|
NumberType(EndianType endianType) |
Modifier and Type | Method and Description |
---|---|
abstract int |
compare(boolean unsignedType,
Number extractedValue,
Number testValue)
Return -1 if extractedValue is < testValue, 1 if it is >, 0 if it is equals.
|
Object |
convertTestString(String typeStr,
String testStr)
Converts the test-string from the magic line to be the testValue object to be passed into
MagicMatcher.isMatch(Object, Long, boolean, Object, MutableOffset, byte[]) and MagicMatcher.getStartingBytes(Object) . |
abstract Number |
decodeValueString(String valueStr)
Decode the test string value.
|
Object |
extractValueFromBytes(int offset,
byte[] bytes,
boolean required)
Extract the value from the bytes either for doing the match or rendering it in the format.
|
abstract int |
getBytesPerType()
Return the number of bytes in this type.
|
Object |
isMatch(Object testValue,
Long andValue,
boolean unsignedType,
Object extractedValue,
MagicMatcher.MutableOffset mutableOffset,
byte[] bytes)
Matches if the bytes match at a certain offset.
|
abstract long |
maskValue(long value)
Return the value with the appropriate bytes masked off corresponding to the bytes in the type.
|
void |
renderValue(StringBuilder sb,
Object extractedValue,
MagicFormatter formatter)
Returns the string version of the extracted value.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getStartingBytes
protected final EndianConverter endianConverter
public NumberType(EndianType endianType)
public abstract Number decodeValueString(String valueStr) throws NumberFormatException
NumberFormatException
public abstract int getBytesPerType()
public abstract int compare(boolean unsignedType, Number extractedValue, Number testValue)
public abstract long maskValue(long value)
public Object convertTestString(String typeStr, String testStr)
MagicMatcher
MagicMatcher.isMatch(Object, Long, boolean, Object, MutableOffset, byte[])
and MagicMatcher.getStartingBytes(Object)
.convertTestString
in interface MagicMatcher
public Object extractValueFromBytes(int offset, byte[] bytes, boolean required)
MagicMatcher
extractValueFromBytes
in interface MagicMatcher
offset
- Number of bytes into the bytes array that we are extracting from.bytes
- Array of bytes we are extracting from.required
- Whether or not the extracted value is required for later. If it is not then the type may opt to not
extract the value and to do the matching directly.MagicMatcher.isMatch(Object, Long, boolean, Object, MutableOffset, byte[])
or null
if not enough bytes.public Object isMatch(Object testValue, Long andValue, boolean unsignedType, Object extractedValue, MagicMatcher.MutableOffset mutableOffset, byte[] bytes)
MagicMatcher
isMatch
in interface MagicMatcher
public void renderValue(StringBuilder sb, Object extractedValue, MagicFormatter formatter)
MagicMatcher
renderValue
in interface MagicMatcher
This content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.