in proton-j/src/main/java/org/apache/qpid/proton/codec/MapType.java [244:301]
public Map readValue()
{
final DecoderImpl decoder = getDecoder();
final ReadableBuffer buffer = decoder.getBuffer();
final int size = decoder.readRawInt();
// todo - limit the decoder with size
final int count = decoder.readRawInt();
if (count > decoder.getByteBufferRemaining()) {
throw new IllegalArgumentException("Map element count "+count+" is specified to be greater than the amount of data available ("+
decoder.getByteBufferRemaining()+")");
}
TypeConstructor<?> keyConstructor = null;
TypeConstructor<?> valueConstructor = null;
Map<Object, Object> map = new LinkedHashMap<>(count);
for(int i = 0; i < count / 2; i++)
{
keyConstructor = findNextDecoder(decoder, buffer, keyConstructor);
if(keyConstructor == null)
{
throw new DecodeException("Unknown constructor");
}
final Object key = keyConstructor.readValue();
boolean arrayType = false;
final byte code = buffer.get(buffer.position());
switch (code)
{
case EncodingCodes.ARRAY8:
case EncodingCodes.ARRAY32:
arrayType = true;
}
valueConstructor = findNextDecoder(decoder, buffer, valueConstructor);
if (valueConstructor == null)
{
throw new DecodeException("Unknown constructor");
}
final Object value;
if (arrayType)
{
value = ((ArrayType.ArrayEncoding) valueConstructor).readValueArray();
}
else
{
value = valueConstructor.readValue();
}
map.put(key, value);
}
return map;
}