Java Code Examples for co.nstant.in.cbor.model.DataItem#setTag()

The following examples show how to use co.nstant.in.cbor.model.DataItem#setTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CborDecoder.java    From cbor-java with Apache License 2.0 4 votes vote down vote up
/**
 * Decodes exactly one DataItem from the input stream.
 *
 * @return a {@link DataItem} or null if end of stream has reached.
 * @throws CborException if decoding failed
 */
public DataItem decodeNext() throws CborException {
    int symbol;
    try {
        symbol = inputStream.read();
    } catch (IOException ioException) {
        throw new CborException(ioException);
    }
    if (symbol == -1) {
        return null;
    }
    switch (MajorType.ofByte(symbol)) {
    case ARRAY:
        return arrayDecoder.decode(symbol);
    case BYTE_STRING:
        return byteStringDecoder.decode(symbol);
    case MAP:
        return mapDecoder.decode(symbol);
    case NEGATIVE_INTEGER:
        return negativeIntegerDecoder.decode(symbol);
    case UNICODE_STRING:
        return unicodeStringDecoder.decode(symbol);
    case UNSIGNED_INTEGER:
        return unsignedIntegerDecoder.decode(symbol);
    case SPECIAL:
        return specialDecoder.decode(symbol);
    case TAG:
        Tag tag = tagDecoder.decode(symbol);
        DataItem next = decodeNext();
        if (next == null) {
            throw new CborException("Unexpected end of stream: tag without following data item.");
        } else {
            if (autoDecodeRationalNumbers && tag.getValue() == 30) {
                return decodeRationalNumber(next);
            } else if (autoDecodeLanguageTaggedStrings && tag.getValue() == 38) {
                return decodeLanguageTaggedString(next);
            } else {
                DataItem itemToTag = next;
                while (itemToTag.hasTag())
                    itemToTag = itemToTag.getTag();
                itemToTag.setTag(tag);
                return next;
            }
        }
    case INVALID:
    default:
        throw new CborException("Not implemented major type " + symbol);
    }
}
 
Example 2
Source File: MapEntryBuilder.java    From cbor-java with Apache License 2.0 4 votes vote down vote up
public MapEntryBuilder<T> tagged(long tag) {
    DataItem item = key.getOuterTaggable();
    item.setTag(tag);
    return this;
}
 
Example 3
Source File: Example48Test.java    From cbor-java with Apache License 2.0 4 votes vote down vote up
public Example48Test() {
    DataItem di = new UnicodeString("2013-03-21T20:04:00Z");
    di.setTag(0);

    VALUE = new CborBuilder().add(di).build();
}
 
Example 4
Source File: Example49Test.java    From cbor-java with Apache License 2.0 4 votes vote down vote up
public Example49Test() {
    DataItem di = new UnsignedInteger(1363896240);
    di.setTag(1);

    VALUE = new CborBuilder().add(di).build();
}
 
Example 5
Source File: Example52Test.java    From cbor-java with Apache License 2.0 4 votes vote down vote up
public Example52Test() {
    DataItem di = new ByteString(new byte[] { 0x64, 0x49, 0x45, 0x54, 0x46 });
    di.setTag(24);

    VALUE = new CborBuilder().add(di).build();
}
 
Example 6
Source File: Example51Test.java    From cbor-java with Apache License 2.0 4 votes vote down vote up
public Example51Test() {
    DataItem di = new ByteString(new byte[] { 0x01, 0x02, 0x03, 0x04 });
    di.setTag(23);

    VALUE = new CborBuilder().add(di).build();
}
 
Example 7
Source File: Example53Test.java    From cbor-java with Apache License 2.0 4 votes vote down vote up
public Example53Test() {
    DataItem di = new UnicodeString("http://www.example.com");
    di.setTag(32);

    VALUE = new CborBuilder().add(di).build();
}
 
Example 8
Source File: Example50Test.java    From cbor-java with Apache License 2.0 4 votes vote down vote up
public Example50Test() {
    DataItem di = new DoublePrecisionFloat(1363896240.5);
    di.setTag(1);

    VALUE = new CborBuilder().add(di).build();
}