in src/com/amazon/ion/impl/IonReaderBinaryRawX.java [466:542]
private final int read_type_id() throws IOException
{
long start_of_tid = _input.getPosition();
long start_of_value = start_of_tid + 1;
int td = read();
if (td < 0) {
return UnifiedInputStreamX.EOF;
}
int tid = _Private_IonConstants.getTypeCode(td);
int len = _Private_IonConstants.getLowNibble(td);
// NOP Padding
if (tid == _Private_IonConstants.tidNull && len != _Private_IonConstants.lnIsNull) {
if (len == _Private_IonConstants.lnIsVarLen) {
len = readVarUInt();
}
_state = _is_in_struct ? State.S_BEFORE_FIELD : State.S_BEFORE_TID;
tid = _Private_IonConstants.tidNopPad; // override typeId to use Pad marker
}
else if (len == _Private_IonConstants.lnIsVarLen) {
len = readVarUInt();
start_of_value = _input.getPosition();
}
else if (tid == _Private_IonConstants.tidNull) {
_value_is_null = true;
len = 0;
_state = State.S_AFTER_VALUE;
}
else if (len == _Private_IonConstants.lnIsNull) {
_value_is_null = true;
len = 0;
_state = State.S_AFTER_VALUE;
}
else if (tid == _Private_IonConstants.tidBoolean) {
switch (len) {
case _Private_IonConstants.lnBooleanFalse:
_value_is_true = false;
break;
case _Private_IonConstants.lnBooleanTrue:
_value_is_true = true;
break;
default:
throwErrorAt("invalid length nibble in boolean value: "+len);
break;
}
len = 0;
_state = State.S_AFTER_VALUE;
}
else if (tid == _Private_IonConstants.tidStruct) {
if ((_struct_is_ordered = (len == 1))) {
// special case of an ordered struct, it gets the
// otherwise impossible to have length of 1
len = readVarUInt();
if (len == 0) {
throwErrorAt("Structs flagged as having ordered keys must contain at least one key/value pair.");
}
start_of_value = _input.getPosition();
}
}
_value_tid = tid;
_value_len = len;
// TODO Keeping track of _value_start is only necessary because top-level
// symbol values are treated differently than all other values: they
// are read during has_next_helper_user in order to compare them
// against the IVM (symbol 2). This behavior is actually contrary to
// the spec, and leads to the reader position being advanced PAST
// the value BEFORE a *Value() method is even called. Once that is fixed,
// _value_start can be removed, and _input._pos can be used to find the
// start of the value at the current valid position.
// amzn/ion-java/issues/88 tracks the fix for bringing IVM handling up to
// spec.
_value_start = start_of_value;
_position_len = len + (start_of_value - start_of_tid);
_position_start = start_of_tid;
return tid;
}