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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations