FileDocCategorySizeDatePackage
Leb128Utils.javaAPI DocAndroid 1.5 API2097Wed May 06 22:41:02 BST 2009com.android.dx.util

Leb128Utils

public final class Leb128Utils extends Object
LEB128 (little-endian base 128) utilities.

Fields Summary
Constructors Summary
private Leb128Utils()
This class is uninstantiable.

        // This space intentionally left blank.
    
Methods Summary
public static intsignedLeb128Size(int value)
Gets the number of bytes in the signed LEB128 encoding of the given value.

param
value the value in question
return
its write size, in bytes

        // TODO: This could be much cleverer.

        int remaining = value >> 7;
        int count = 0;
        boolean hasMore = true;
        int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1;

        while (hasMore) {
            hasMore = (remaining != end)
                || ((remaining & 1) != ((value >> 6) & 1));

            value = remaining;
            remaining >>= 7;
            count++;
        }

        return count;
    
public static intunsignedLeb128Size(int value)
Gets the number of bytes in the unsigned LEB128 encoding of the given value.

param
value the value in question
return
its write size, in bytes

        // TODO: This could be much cleverer.
        
        int remaining = value >> 7;
        int count = 0;

        while (remaining != 0) {
            value = remaining;
            remaining >>= 7;
            count++;
        }

        return count + 1;