Pull parser for encoded values.
| 22 | * Pull parser for encoded values. |
| 23 | */ |
| 24 | public final class EncodedValueReader { |
| 25 | public static final int ENCODED_BYTE = 0x00; |
| 26 | public static final int ENCODED_SHORT = 0x02; |
| 27 | public static final int ENCODED_CHAR = 0x03; |
| 28 | public static final int ENCODED_INT = 0x04; |
| 29 | public static final int ENCODED_LONG = 0x06; |
| 30 | public static final int ENCODED_FLOAT = 0x10; |
| 31 | public static final int ENCODED_DOUBLE = 0x11; |
| 32 | public static final int ENCODED_METHOD_TYPE = 0x15; |
| 33 | public static final int ENCODED_METHOD_HANDLE = 0x16; |
| 34 | public static final int ENCODED_STRING = 0x17; |
| 35 | public static final int ENCODED_TYPE = 0x18; |
| 36 | public static final int ENCODED_FIELD = 0x19; |
| 37 | public static final int ENCODED_ENUM = 0x1b; |
| 38 | public static final int ENCODED_METHOD = 0x1a; |
| 39 | public static final int ENCODED_ARRAY = 0x1c; |
| 40 | public static final int ENCODED_ANNOTATION = 0x1d; |
| 41 | public static final int ENCODED_NULL = 0x1e; |
| 42 | public static final int ENCODED_BOOLEAN = 0x1f; |
| 43 | |
| 44 | /** placeholder type if the type is not yet known */ |
| 45 | private static final int MUST_READ = -1; |
| 46 | |
| 47 | protected final ByteInput in; |
| 48 | private int type = MUST_READ; |
| 49 | private int annotationType; |
| 50 | private int arg; |
| 51 | |
| 52 | public EncodedValueReader(ByteInput in) { |
| 53 | this.in = in; |
| 54 | } |
| 55 | |
| 56 | public EncodedValueReader(EncodedValue in) { |
| 57 | this(in.asByteInput()); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates a new encoded value reader whose only value is the specified |
| 62 | * known type. This is useful for encoded values without a type prefix, |
| 63 | * such as class_def_item's encoded_array or annotation_item's |
| 64 | * encoded_annotation. |
| 65 | */ |
| 66 | public EncodedValueReader(ByteInput in, int knownType) { |
| 67 | this.in = in; |
| 68 | this.type = knownType; |
| 69 | } |
| 70 | |
| 71 | public EncodedValueReader(EncodedValue in, int knownType) { |
| 72 | this(in.asByteInput(), knownType); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Returns the type of the next value to read. |
| 77 | */ |
| 78 | public int peek() { |
| 79 | if (type == MUST_READ) { |
| 80 | int argAndType = in.readByte() & 0xff; |
| 81 | type = argAndType & 0x1f; |
nothing calls this directly
no outgoing calls
no test coverage detected