in src/com/amazon/ion/impl/IonReaderBinaryRawX.java [258:342]
private final void has_next_helper_raw() throws IOException
{
clear_value();
while (_value_tid == -1 && !_eof) {
switch (_state) {
case S_BEFORE_FIELD:
assert _value_field_id == SymbolTable.UNKNOWN_SYMBOL_ID;
_value_field_id = read_field_id();
if (_value_field_id == UnifiedInputStreamX.EOF) {
// FIXME why is EOF ever okay in the middle of a struct?
assert UnifiedInputStreamX.EOF == SymbolTable.UNKNOWN_SYMBOL_ID;
_eof = true;
break;
}
// fall through to try to read the type id right now
case S_BEFORE_TID:
_state = State.S_BEFORE_VALUE; // read_type_id may change this for null and bool values
_value_tid = read_type_id();
if (_value_tid == UnifiedInputStreamX.EOF) {
_state = State.S_EOF;
_eof = true;
break;
}
if (_value_tid == _Private_IonConstants.tidNopPad) {
// skips size of pad and resets State machine
skip(_value_len);
clear_value();
break;
}
else if (_value_tid == _Private_IonConstants.tidTypedecl) {
assert (_value_tid == (BINARY_VERSION_MARKER_TID & 0xff)); // the bvm tid happens to be type decl
if (_value_len == BINARY_VERSION_MARKER_LEN ) {
// this isn't valid for any type descriptor except the first byte
// of a 4 byte version marker - so lets read the rest
load_version_marker();
_value_type = IonType.SYMBOL;
}
else {
// if it's not a bvm then it's an ordinary annotated value
// The next call changes our positions to that of the
// wrapped value, but we need to remember the overall
// wrapper position.
long wrapperStart = _position_start;
long wrapperLen = _position_len;
_value_type = load_annotation_start_with_value_type();
// Wrapper and wrapped value should finish together!
long wrapperFinish = wrapperStart + wrapperLen;
long wrappedValueFinish = _position_start + _position_len;
if (wrapperFinish != wrappedValueFinish) {
throw newErrorAt(String.format("Wrapper length mismatch: wrapper %s wrapped value %s", wrapperFinish, wrappedValueFinish));
}
_position_start = wrapperStart;
_position_len = wrapperLen;
}
}
else {
// if it's not a typedesc then we just get the IonType and we're done
_value_type = get_iontype_from_tid(_value_tid);
}
break;
case S_BEFORE_VALUE:
skip(_value_len);
// fall through to "after value"
case S_AFTER_VALUE:
if (isInStruct()) {
_state = State.S_BEFORE_FIELD;
}
else {
_state = State.S_BEFORE_TID;
}
break;
case S_EOF:
break;
default:
error("internal error: raw binary reader in invalid state!");
}
}
// we always want to exit here
_has_next_needed = false;
return;
}