Search in sources :

Example 21 with SymbolToken

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);
    }
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolToken(com.amazon.ion.SymbolToken) ArrayList(java.util.ArrayList)

Example 22 with SymbolToken

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);
    }
}
Also used : SymbolToken(com.amazon.ion.SymbolToken)

Example 23 with SymbolToken

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);
    }
}
Also used : SymbolToken(com.amazon.ion.SymbolToken)

Example 24 with SymbolToken

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;
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) SymbolTable(com.amazon.ion.SymbolTable)

Example 25 with SymbolToken

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;
}
Also used : SymbolToken(com.amazon.ion.SymbolToken)

Aggregations

SymbolToken (com.amazon.ion.SymbolToken)68 SymbolTable (com.amazon.ion.SymbolTable)14 com.amazon.ion.impl._Private_Utils.newSymbolToken (com.amazon.ion.impl._Private_Utils.newSymbolToken)13 IonType (com.amazon.ion.IonType)10 IonValue (com.amazon.ion.IonValue)10 IonException (com.amazon.ion.IonException)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 IonStruct (com.amazon.ion.IonStruct)4 IOException (java.io.IOException)4 Event (com.amazon.tools.events.Event)3 EventType (com.amazon.tools.events.EventType)3 FakeSymbolToken (com.amazon.ion.FakeSymbolToken)2 IonDatagram (com.amazon.ion.IonDatagram)2 IonSequence (com.amazon.ion.IonSequence)2 IonString (com.amazon.ion.IonString)2 UnknownSymbolException (com.amazon.ion.UnknownSymbolException)2 SavePoint (com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint)2 ImportDescriptor (com.amazon.tools.events.ImportDescriptor)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2