use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class ReverseBinaryEncoder method writeIonStructContent.
private void writeIonStructContent(IonStruct val) {
if (val.isNullValue()) {
writeByte((byte) (TYPE_STRUCT | NULL_LENGTH_MASK));
} else {
final int originalOffset = myBuffer.length - myOffset;
// TODO amzn/ion-java/issues/31 should not preserve the ordering of fields
ArrayList<IonValue> values = new ArrayList<IonValue>();
// references of the IonValues
for (IonValue curr : val) {
values.add(curr);
}
for (int i = values.size(); --i >= 0; ) {
IonValue v = values.get(i);
SymbolToken symToken = v.getFieldNameSymbol();
writeIonValue(v);
int sid = findSid(symToken);
writeVarUInt(sid);
}
// TODO amzn/ion-java/issues/41 Detect if the struct fields are sorted in ascending
// order of Sids. If so, 1 should be written into 'length' field.
// Note that this 'length' field is not the same as the four-bit
// length L in the type descriptor octet.
writePrefix(TYPE_STRUCT, myBuffer.length - myOffset - originalOffset);
}
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class ReverseBinaryEncoder method writeIonSymbolContent.
private void writeIonSymbolContent(IonSymbol val) {
if (val.isNullValue()) {
writeByte((byte) (TYPE_SYMBOL | NULL_LENGTH_MASK));
} else {
final int originalOffset = myBuffer.length - myOffset;
SymbolToken symToken = val.symbolValue();
int sid = findSid(symToken);
writeUInt(sid);
writePrefix(TYPE_SYMBOL, myBuffer.length - myOffset - originalOffset);
}
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class _Private_IonWriterBase method write_value_field_name_helper.
/**
* @throws UnknownSymbolException if the text of the field name is
* unknown.
*/
private final void write_value_field_name_helper(IonReader reader) {
if (this.isInStruct() && !isFieldNameSet()) {
SymbolToken tok = reader.getFieldNameSymbol();
if (tok == null) {
throw new IllegalStateException("Field name not set");
}
setFieldNameSymbol(tok);
}
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonSymbolLite method getSymbolId.
private int getSymbolId(SymbolTableProvider symbolTableProvider) throws NullValueException {
validateThisNotNull();
if (_sid != UNKNOWN_SYMBOL_ID || isReadOnly()) {
return _sid;
}
SymbolTable symtab = symbolTableProvider != null ? symbolTableProvider.getSymbolTable() : getSymbolTable();
if (symtab == null) {
symtab = getSystem().getSystemSymbolTable();
}
assert (symtab != null);
String name = _get_value();
// TODO [amzn/ion-java/issues/27] - needs consistent handling, when to retain SID's vs ignore (here memoizing SID on read)
if (!symtab.isLocalTable()) {
setSID(symtab.findSymbol(name));
if (_sid > 0 || isReadOnly()) {
return _sid;
}
}
SymbolToken tok = symtab.find(name);
if (tok != null) {
setSID(tok.getSid());
// Use the interned instance of the text
_set_value(tok.getText());
}
return _sid;
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class _Private_Utils method localize.
public static SymbolToken localize(SymbolTable symtab, SymbolToken sym) {
String text = sym.getText();
int sid = sym.getSid();
if (// TODO amzn/ion-java/issues/21 require symtab
symtab != null) {
if (text == null) {
text = symtab.findKnownSymbol(sid);
if (text != null) {
sym = new SymbolTokenImpl(text, sid);
}
} else {
SymbolToken newSym = symtab.find(text);
if (newSym != null) {
sym = newSym;
} else if (sid >= 0) {
// We can't trust the sid, discard it.
sym = new SymbolTokenImpl(text, UNKNOWN_SYMBOL_ID);
}
}
} else if (text != null && sid >= 0) {
// We can't trust the sid, discard it.
sym = new SymbolTokenImpl(text, UNKNOWN_SYMBOL_ID);
}
return sym;
}
Aggregations