use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderBinaryUserX method push_symbol_table.
private void push_symbol_table(SymbolTable symbols) {
assert (symbols != null);
if (_symbol_table_top >= _symbol_table_stack.length) {
int new_len = _symbol_table_stack.length * 2;
SymbolTable[] temp = new SymbolTable[new_len];
System.arraycopy(_symbol_table_stack, 0, temp, 0, _symbol_table_stack.length);
_symbol_table_stack = temp;
}
_symbol_table_stack[_symbol_table_top++] = symbols;
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderBinaryIncremental method readSymbolTable.
/**
* Reads a local symbol table from the buffer.
* @param marker marker for the start and end positions of the local symbol table in the buffer.
*/
private void readSymbolTable(IonReaderLookaheadBuffer.Marker marker) {
peekIndex = marker.startIndex;
boolean isAppend = false;
boolean hasSeenImports = false;
boolean hasSeenSymbols = false;
int symbolsPosition = -1;
int symbolsEndPosition = -1;
List<SymbolTable> newImports;
while (peekIndex < marker.endIndex) {
fieldNameSid = readVarUInt();
IonTypeID typeID = readTypeId();
calculateEndPosition(typeID);
int currentValueEndPosition = valueEndPosition;
if (fieldNameSid == SystemSymbolIDs.IMPORTS_ID) {
if (hasSeenImports) {
throw new IonException("Symbol table contained multiple imports fields.");
}
if (typeID.type == IonType.SYMBOL) {
isAppend = readUInt(peekIndex, currentValueEndPosition) == SystemSymbolIDs.ION_SYMBOL_TABLE_ID;
peekIndex = currentValueEndPosition;
} else if (typeID.type == IonType.LIST) {
resetImports();
newImports = new ArrayList<SymbolTable>(3);
newImports.add(getSystemSymbolTable());
stepIn();
IonType type = next();
while (type != null) {
String name = null;
int version = -1;
int maxId = -1;
if (type == IonType.STRUCT) {
stepIn();
type = next();
while (type != null) {
int fieldSid = getFieldId();
if (fieldSid == SystemSymbolIDs.NAME_ID) {
if (type == IonType.STRING) {
name = stringValue();
}
} else if (fieldSid == SystemSymbolIDs.VERSION_ID) {
if (type == IonType.INT) {
version = intValue();
}
} else if (fieldSid == SystemSymbolIDs.MAX_ID_ID) {
if (type == IonType.INT) {
maxId = intValue();
}
}
type = next();
}
stepOut();
}
newImports.add(createImport(name, version, maxId));
type = next();
}
stepOut();
imports = new LocalSymbolTableImports(newImports);
}
if (!isAppend) {
// Clear the existing symbols before adding the new imported symbols.
resetSymbolTable();
}
hasSeenImports = true;
} else if (fieldNameSid == SystemSymbolIDs.SYMBOLS_ID) {
if (hasSeenSymbols) {
throw new IonException("Symbol table contained multiple symbols fields.");
}
if (typeID.type == IonType.LIST) {
// Just record this position and skip forward. Come back after the imports (if any) are parsed.
symbolsPosition = peekIndex;
symbolsEndPosition = currentValueEndPosition;
}
hasSeenSymbols = true;
}
peekIndex = currentValueEndPosition;
}
if (!hasSeenImports) {
resetSymbolTable();
resetImports();
}
if (symbolsPosition > -1) {
peekIndex = symbolsPosition;
valueType = IonType.LIST;
valueEndPosition = symbolsEndPosition;
stepIn();
while (next() != null) {
if (valueType != IonType.STRING) {
symbols.add(null);
} else {
symbols.add(stringValue());
}
}
stepOut();
peekIndex = valueEndPosition;
}
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderTextSystemX method getFieldId.
@Override
public final int getFieldId() {
// Superclass handles hoisting logic
int id = super.getFieldId();
if (id == SymbolTable.UNKNOWN_SYMBOL_ID) {
String fieldname = getRawFieldName();
if (fieldname != null) {
SymbolTable symbols = getSymbolTable();
id = symbols.findSymbol(fieldname);
}
}
return id;
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderTextUserX method pop_passed_symbol_table.
@Override
public SymbolTable pop_passed_symbol_table() {
if (_symbol_table_top <= 0) {
return null;
}
_symbol_table_top--;
SymbolTable symbols = _symbol_table_stack[_symbol_table_top];
_symbol_table_stack[_symbol_table_top] = null;
return symbols;
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderTreeUserX method next_helper_user.
boolean next_helper_user() {
if (_eof)
return false;
if (_next != null)
return true;
clear_system_value_stack();
// read values from the system
// reader and if they are system values
// process them. Return when we've
// read all the immediate system values
IonType next_type;
for (; ; ) {
next_type = next_helper_system();
if (_top == 0 && _parent instanceof IonDatagram) {
if (IonType.SYMBOL.equals(next_type)) {
assert (_next instanceof IonSymbol);
IonSymbol sym = (IonSymbol) _next;
if (sym.isNullValue()) {
// there are no null values we will consume here
break;
}
int sid = sym.getSymbolId();
if (sid == UNKNOWN_SYMBOL_ID) {
String name = sym.stringValue();
if (name != null) {
sid = _system_symtab.findSymbol(name);
}
}
if (sid == ION_1_0_SID && _next.getTypeAnnotationSymbols().length == 0) {
// $ion_1_0 is read as an IVM only if it is not annotated
SymbolTable symbols = _system_symtab;
_symbols = symbols;
push_symbol_table(symbols);
_next = null;
continue;
}
} else if (IonType.STRUCT.equals(next_type) && _next.findTypeAnnotation(ION_SYMBOL_TABLE) == 0) {
assert (_next instanceof IonStruct);
// read a local symbol table
IonReader reader = new IonReaderTreeUserX(_next, _catalog, _lstFactory);
SymbolTable symtab = _lstFactory.newLocalSymtab(_catalog, reader, false);
_symbols = symtab;
push_symbol_table(symtab);
_next = null;
continue;
}
}
// so this is a value the user gets
break;
}
return (next_type != null);
}
Aggregations