Search in sources :

Example 1 with MapTypeDecoder

use of org.apache.qpid.protonj2.codec.decoders.primitives.MapTypeDecoder in project qpid-protonj2 by apache.

the class DeliveryAnnotationsTypeDecoder method readMap.

private Map<Symbol, Object> readMap(ProtonBuffer buffer, DecoderState state, MapTypeDecoder mapDecoder) throws DecodeException {
    final int size = mapDecoder.readSize(buffer);
    final int count = mapDecoder.readCount(buffer);
    if (count > buffer.getReadableBytes()) {
        throw new DecodeException(String.format("Map encoded size %d is specified to be greater than the amount " + "of data available (%d)", size, buffer.getReadableBytes()));
    }
    // Count include both key and value so we must include that in the loop
    final Map<Symbol, Object> map = new LinkedHashMap<>(count);
    for (int i = 0; i < count / 2; i++) {
        Symbol key = state.getDecoder().readSymbol(buffer, state);
        Object value = state.getDecoder().readObject(buffer, state);
        map.put(key, value);
    }
    return map;
}
Also used : Symbol(org.apache.qpid.protonj2.types.Symbol) DecodeException(org.apache.qpid.protonj2.codec.DecodeException) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with MapTypeDecoder

use of org.apache.qpid.protonj2.codec.decoders.primitives.MapTypeDecoder in project qpid-protonj2 by apache.

the class MessageAnnotationsTypeDecoder method readMap.

private Map<Symbol, Object> readMap(ProtonBuffer buffer, DecoderState state, MapTypeDecoder mapDecoder) throws DecodeException {
    final int size = mapDecoder.readSize(buffer);
    final int count = mapDecoder.readCount(buffer);
    if (count > buffer.getReadableBytes()) {
        throw new DecodeException(String.format("Map encoded size %d is specified to be greater than the amount " + "of data available (%d)", size, buffer.getReadableBytes()));
    }
    // Count include both key and value so we must include that in the loop
    final Map<Symbol, Object> map = new LinkedHashMap<>(count);
    for (int i = 0; i < count / 2; i++) {
        Symbol key = state.getDecoder().readSymbol(buffer, state);
        Object value = state.getDecoder().readObject(buffer, state);
        map.put(key, value);
    }
    return map;
}
Also used : Symbol(org.apache.qpid.protonj2.types.Symbol) DecodeException(org.apache.qpid.protonj2.codec.DecodeException) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with MapTypeDecoder

use of org.apache.qpid.protonj2.codec.decoders.primitives.MapTypeDecoder in project qpid-protonj2 by apache.

the class MessageAnnotationsTypeDecoder method readMap.

private Map<Symbol, Object> readMap(InputStream stream, StreamDecoderState state, MapTypeDecoder mapDecoder) throws DecodeException {
    @SuppressWarnings("unused") final int size = mapDecoder.readSize(stream);
    final int count = mapDecoder.readCount(stream);
    // Count include both key and value so we must include that in the loop
    final Map<Symbol, Object> map = new LinkedHashMap<>(count);
    for (int i = 0; i < count / 2; i++) {
        Symbol key = state.getDecoder().readSymbol(stream, state);
        Object value = state.getDecoder().readObject(stream, state);
        map.put(key, value);
    }
    return map;
}
Also used : Symbol(org.apache.qpid.protonj2.types.Symbol) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with MapTypeDecoder

use of org.apache.qpid.protonj2.codec.decoders.primitives.MapTypeDecoder in project qpid-protonj2 by apache.

the class FooterTypeDecoder method readArrayElements.

@SuppressWarnings("unchecked")
@Override
public Footer[] readArrayElements(InputStream stream, StreamDecoderState state, int count) throws DecodeException {
    final StreamTypeDecoder<?> decoder = state.getDecoder().readNextTypeDecoder(stream, state);
    final Footer[] result = new Footer[count];
    if (decoder instanceof NullTypeDecoder) {
        for (int i = 0; i < count; ++i) {
            decoder.readValue(stream, state);
            result[i] = new Footer(null);
        }
        return result;
    }
    final MapTypeDecoder mapDecoder = checkIsExpectedTypeAndCast(MapTypeDecoder.class, decoder);
    for (int i = 0; i < count; ++i) {
        result[i] = new Footer(mapDecoder.readValue(stream, state));
    }
    return result;
}
Also used : NullTypeDecoder(org.apache.qpid.protonj2.codec.decoders.primitives.NullTypeDecoder) Footer(org.apache.qpid.protonj2.types.messaging.Footer) MapTypeDecoder(org.apache.qpid.protonj2.codec.decoders.primitives.MapTypeDecoder)

Example 5 with MapTypeDecoder

use of org.apache.qpid.protonj2.codec.decoders.primitives.MapTypeDecoder in project qpid-protonj2 by apache.

the class ApplicationPropertiesTypeDecoder method readMap.

private Map<String, Object> readMap(InputStream stream, StreamDecoderState state, MapTypeDecoder mapDecoder) throws DecodeException {
    @SuppressWarnings("unused") final int size = mapDecoder.readSize(stream);
    final int count = mapDecoder.readCount(stream);
    final StreamDecoder decoder = state.getDecoder();
    // Count include both key and value so we must include that in the loop
    final Map<String, Object> map = new LinkedHashMap<>(count);
    for (int i = 0; i < count / 2; i++) {
        String key = decoder.readString(stream, state);
        Object value = decoder.readObject(stream, state);
        map.put(key, value);
    }
    return map;
}
Also used : StreamDecoder(org.apache.qpid.protonj2.codec.StreamDecoder) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

MapTypeDecoder (org.apache.qpid.protonj2.codec.decoders.primitives.MapTypeDecoder)7 NullTypeDecoder (org.apache.qpid.protonj2.codec.decoders.primitives.NullTypeDecoder)7 LinkedHashMap (java.util.LinkedHashMap)6 Symbol (org.apache.qpid.protonj2.types.Symbol)4 Footer (org.apache.qpid.protonj2.types.messaging.Footer)4 DecodeException (org.apache.qpid.protonj2.codec.DecodeException)3 StreamDecoder (org.apache.qpid.protonj2.codec.StreamDecoder)2 MessageAnnotations (org.apache.qpid.protonj2.types.messaging.MessageAnnotations)2 Decoder (org.apache.qpid.protonj2.codec.Decoder)1 StreamTypeDecoder (org.apache.qpid.protonj2.codec.StreamTypeDecoder)1 TypeDecoder (org.apache.qpid.protonj2.codec.TypeDecoder)1 AbstractDescribedTypeDecoder (org.apache.qpid.protonj2.codec.decoders.AbstractDescribedTypeDecoder)1