org.ow2.asmdex.encodedValue
Class EncodedValueUtil

java.lang.Object
  extended by org.ow2.asmdex.encodedValue.EncodedValueUtil

public class EncodedValueUtil
extends java.lang.Object

Utility Class for the encoding of Encoded Value.

Author:
Julien Névo

Constructor Summary
EncodedValueUtil()
           
 
Method Summary
static byte encodeHeader(int size, int type)
          Encodes the Header of a Value (the first byte including the value_arg and value_type).
static byte[] encodeSignedValue(int val, int type)
          Returns an encoded_value, including the header.
static byte[] encodeSignedValue(long val, int type)
          Returns an encoded_value (long), including the header.
static byte[] encodeUnsignedValue(int val, int type)
          Returns an unsigned encoded_value, including the header.
static byte[] encodeZeroExtendedToRightValue(long val, int type)
          Returns an zero-extended-to-the-right encoded_value, including the header.
static int getNbBytesForRightZeroExtendedValue(long value)
          Returns the bytes count needed to encoded the given value, zero-extended to the right.
static int getNbBytesInSignedValue(int value)
          Returns the bytes count needed to encode the given signed value.
static int getNbBytesInSignedValue(long value)
          Returns the bytes count needed to encode the given signed value.
static int getTypeFromDescriptor(java.lang.String desc)
          Converts a Descriptor into a Value Type.
static boolean isString(java.lang.String desc)
          Indicates whether the given descriptor is a String.
static boolean isTypeAReference(java.lang.String desc)
          Indicates whether the given descriptor is a reference or a primitive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncodedValueUtil

public EncodedValueUtil()
Method Detail

encodeHeader

public static byte encodeHeader(int size,
                                int type)
Encodes the Header of a Value (the first byte including the value_arg and value_type).

Parameters:
size - actual size of the encoded value (NOT decremented of 1).
type - type of the value.
Returns:
a byte representing the header.

encodeUnsignedValue

public static byte[] encodeUnsignedValue(int val,
                                         int type)
Returns an unsigned encoded_value, including the header.

Parameters:
val - unsigned value to encode.
type - type of the value. This is only needed for the header.
Returns:
an array consisting of an encoded_value and its header.

encodeSignedValue

public static byte[] encodeSignedValue(int val,
                                       int type)
Returns an encoded_value, including the header.

Parameters:
val - value to encode.
type - type of the value. This is only needed for the header.
Returns:
an array consisting of an encoded_value and its header.

encodeSignedValue

public static byte[] encodeSignedValue(long val,
                                       int type)
Returns an encoded_value (long), including the header.

Parameters:
val - value to encode.
type - type of the value. This is only needed for the header.
Returns:
an array consisting of an encoded_value and its header.

encodeZeroExtendedToRightValue

public static byte[] encodeZeroExtendedToRightValue(long val,
                                                    int type)
Returns an zero-extended-to-the-right encoded_value, including the header.

Parameters:
val - value to encode.
type - type of the value. This is only needed for the header.
Returns:
an array consisting of an encoded_value and its header.

getNbBytesInSignedValue

public static int getNbBytesInSignedValue(long value)
Returns the bytes count needed to encode the given signed value.

Parameters:
value - the signed value.
Returns:
the bytes count needed to encode the value.

getNbBytesInSignedValue

public static int getNbBytesInSignedValue(int value)
Returns the bytes count needed to encode the given signed value.

Parameters:
value - the signed value.
Returns:
the bytes count needed to encode the value.

getNbBytesForRightZeroExtendedValue

public static int getNbBytesForRightZeroExtendedValue(long value)
Returns the bytes count needed to encoded the given value, zero-extended to the right.

Parameters:
value - the value.
Returns:
the bytes count needed to encode the value.

getTypeFromDescriptor

public static int getTypeFromDescriptor(java.lang.String desc)
Converts a Descriptor into a Value Type. Works only for primitives.

Parameters:
desc - descriptor. Should contain only one element, only the first is taken in account.
Returns:
the value type, see Opcodes.

isTypeAReference

public static boolean isTypeAReference(java.lang.String desc)
Indicates whether the given descriptor is a reference or a primitive.

Parameters:
desc - descriptor. Should contain only one element, only the first is taken in account.
Returns:
true if the given descriptor is a reference.

isString

public static boolean isString(java.lang.String desc)
Indicates whether the given descriptor is a String.

Parameters:
desc - descriptor. Should contain only one element.
Returns:
true if the given descriptor is a String.