use of org.apache.qpid.protonj2.types.messaging.MessageAnnotations in project qpid-protonj2 by apache.
the class MessageAnnotationsTypeDecoder method readArrayElements.
@Override
public MessageAnnotations[] readArrayElements(InputStream stream, StreamDecoderState state, int count) throws DecodeException {
final StreamTypeDecoder<?> decoder = state.getDecoder().readNextTypeDecoder(stream, state);
final MessageAnnotations[] result = new MessageAnnotations[count];
if (decoder instanceof NullTypeDecoder) {
for (int i = 0; i < count; ++i) {
decoder.readValue(stream, state);
result[i] = new MessageAnnotations(null);
}
return result;
}
final MapTypeDecoder mapDecoder = checkIsExpectedTypeAndCast(MapTypeDecoder.class, decoder);
for (int i = 0; i < count; ++i) {
result[i] = new MessageAnnotations(readMap(stream, state, mapDecoder));
}
return result;
}
use of org.apache.qpid.protonj2.types.messaging.MessageAnnotations in project qpid-protonj2 by apache.
the class MessageAnnotationsTypeDecoder method readArrayElements.
@Override
public MessageAnnotations[] readArrayElements(ProtonBuffer buffer, DecoderState state, int count) throws DecodeException {
final TypeDecoder<?> decoder = state.getDecoder().readNextTypeDecoder(buffer, state);
final MessageAnnotations[] result = new MessageAnnotations[count];
if (decoder instanceof NullTypeDecoder) {
for (int i = 0; i < count; ++i) {
decoder.readValue(buffer, state);
result[i] = new MessageAnnotations(null);
}
return result;
}
final MapTypeDecoder mapDecoder = checkIsExpectedTypeAndCast(MapTypeDecoder.class, decoder);
for (int i = 0; i < count; ++i) {
result[i] = new MessageAnnotations(readMap(buffer, state, mapDecoder));
}
return result;
}
use of org.apache.qpid.protonj2.types.messaging.MessageAnnotations in project qpid-protonj2 by apache.
the class Benchmark method benchmarkMessageAnnotations.
private void benchmarkMessageAnnotations() throws IOException {
MessageAnnotations annotations = new MessageAnnotations(new HashMap<>());
annotations.getValue().put(Symbol.valueOf("test1"), UnsignedByte.valueOf((byte) 128));
annotations.getValue().put(Symbol.valueOf("test2"), UnsignedShort.valueOf((short) 128));
annotations.getValue().put(Symbol.valueOf("test3"), UnsignedInteger.valueOf((byte) 128));
resultSet.start();
for (int i = 0; i < ITERATIONS; i++) {
buffer.clear();
encoder.writeObject(buffer, encoderState, annotations);
}
resultSet.encodesComplete();
resultSet.start();
for (int i = 0; i < ITERATIONS; i++) {
buffer.setReadIndex(0);
decoder.readObject(buffer, decoderState);
}
resultSet.decodesComplete();
time("MessageAnnotations", resultSet);
}
use of org.apache.qpid.protonj2.types.messaging.MessageAnnotations in project qpid-protonj2 by apache.
the class MessageAnnotationsBenchmark method initMessageAnnotations.
private void initMessageAnnotations() {
annotations = new MessageAnnotations(new HashMap<Symbol, Object>());
annotations.getValue().put(Symbol.valueOf("test1"), UnsignedByte.valueOf((byte) 128));
annotations.getValue().put(Symbol.valueOf("test2"), UnsignedShort.valueOf((short) 128));
annotations.getValue().put(Symbol.valueOf("test3"), UnsignedInteger.valueOf((byte) 128));
}
use of org.apache.qpid.protonj2.types.messaging.MessageAnnotations in project qpid-protonj2 by apache.
the class MessageAnnotationsTypeCodecTest method doTestEncodeAndDecodeAnnotationsWithEmbeddedMaps.
private void doTestEncodeAndDecodeAnnotationsWithEmbeddedMaps(boolean fromStream) throws IOException {
final Symbol SYMBOL_1 = Symbol.valueOf("x-opt-test1");
final Symbol SYMBOL_2 = Symbol.valueOf("x-opt-test2");
final String VALUE_1 = "string";
final UnsignedInteger VALUE_2 = UnsignedInteger.valueOf(42);
final UUID VALUE_3 = UUID.randomUUID();
Map<String, Object> stringKeyedMap = new HashMap<>();
stringKeyedMap.put("key1", VALUE_1);
stringKeyedMap.put("key2", VALUE_2);
stringKeyedMap.put("key3", VALUE_3);
Map<Symbol, Object> symbolKeyedMap = new HashMap<>();
symbolKeyedMap.put(Symbol.valueOf("key1"), VALUE_1);
symbolKeyedMap.put(Symbol.valueOf("key2"), VALUE_2);
symbolKeyedMap.put(Symbol.valueOf("key3"), VALUE_3);
MessageAnnotations annotations = new MessageAnnotations(new HashMap<>());
annotations.getValue().put(SYMBOL_1, stringKeyedMap);
annotations.getValue().put(SYMBOL_2, symbolKeyedMap);
ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
InputStream stream = new ProtonBufferInputStream(buffer);
encoder.writeObject(buffer, encoderState, annotations);
final Object result;
if (fromStream) {
result = streamDecoder.readObject(stream, streamDecoderState);
} else {
result = decoder.readObject(buffer, decoderState);
}
assertNotNull(result);
assertTrue(result instanceof MessageAnnotations);
MessageAnnotations readAnnotations = (MessageAnnotations) result;
Map<Symbol, Object> resultMap = readAnnotations.getValue();
assertEquals(annotations.getValue().size(), resultMap.size());
assertEquals(resultMap.get(SYMBOL_1), stringKeyedMap);
assertEquals(resultMap.get(SYMBOL_2), symbolKeyedMap);
}
Aggregations