use of org.apache.qpid.protonj2.types.Binary in project qpid-protonj2 by apache.
the class ClientMessageSupport method convertFromOutsideMessage.
// ----- Internal Implementation
private static <E> ClientMessage<E> convertFromOutsideMessage(Message<E> source) throws ClientException {
Header header = new Header();
header.setDurable(source.durable());
header.setPriority(source.priority());
header.setTimeToLive(source.timeToLive());
header.setFirstAcquirer(source.firstAcquirer());
header.setDeliveryCount(source.deliveryCount());
Properties properties = new Properties();
properties.setMessageId(source.messageId());
properties.setUserId(source.userId() != null ? new Binary(source.userId()) : null);
properties.setTo(source.to());
properties.setSubject(source.subject());
properties.setReplyTo(source.replyTo());
properties.setCorrelationId(source.correlationId());
properties.setContentType(source.contentType());
properties.setContentEncoding(source.contentEncoding());
properties.setAbsoluteExpiryTime(source.absoluteExpiryTime());
properties.setCreationTime(source.creationTime());
properties.setGroupId(source.groupId());
properties.setGroupSequence(source.groupSequence());
properties.setReplyToGroupId(source.replyToGroupId());
final MessageAnnotations messageAnnotations;
if (source.hasAnnotations()) {
messageAnnotations = new MessageAnnotations(new LinkedHashMap<>());
source.forEachAnnotation((key, value) -> {
messageAnnotations.getValue().put(Symbol.valueOf(key), value);
});
} else {
messageAnnotations = null;
}
final ApplicationProperties applicationProperties;
if (source.hasProperties()) {
applicationProperties = new ApplicationProperties(new LinkedHashMap<>());
source.forEachProperty((key, value) -> {
applicationProperties.getValue().put(key, value);
});
} else {
applicationProperties = null;
}
final Footer footer;
if (source.hasFooters()) {
footer = new Footer(new LinkedHashMap<>());
source.forEachFooter((key, value) -> {
footer.getValue().put(Symbol.valueOf(key), value);
});
} else {
footer = null;
}
ClientMessage<E> message = new ClientMessage<>(createSectionFromValue(source.body()));
message.header(header);
message.properties(properties);
message.annotations(messageAnnotations);
message.applicationProperties(applicationProperties);
message.footer(footer);
return message;
}
use of org.apache.qpid.protonj2.types.Binary in project qpid-protonj2 by apache.
the class AbstractMessageSectionMatcher method verify.
/**
* @param receivedBinary
* The received Binary value that should be validated.
*
* @return the number of bytes consumed from the provided Binary
*
* @throws RuntimeException
* if the provided Binary does not match expectation in some way
*/
public int verify(ByteBuf receivedBinary) throws RuntimeException {
int length = receivedBinary.readableBytes();
Codec data = Codec.Factory.create();
long decoded = data.decode(receivedBinary);
if (decoded > Integer.MAX_VALUE) {
throw new IllegalStateException("Decoded more bytes than Binary supports holding");
}
if (decoded < length && !expectTrailingBytes) {
throw new IllegalArgumentException("Expected to consume all bytes, but trailing bytes remain: Got " + length + ", consumed " + decoded);
}
DescribedType decodedDescribedType = data.getDescribedType();
verifyReceivedDescribedType(decodedDescribedType);
// Integer.MAX_VALUE
return (int) decoded;
}
use of org.apache.qpid.protonj2.types.Binary in project qpid-protonj2 by apache.
the class DeclareExpectation method accept.
/**
* Indicates a successful transaction declaration by returning a {@link Declared}
* disposition with the given transaction Id.
*
* @param txnId
* byte array containing the transaction id that has been declared.
*
* @return this {@link DispositionInjectAction} instance.
*/
public DispositionInjectAction accept(byte[] txnId) {
response = new DispositionInjectAction(driver);
response.withSettled(true);
if (txnId != null) {
response.withState(new Declared().setTxnId(new Binary(txnId)));
} else {
response.withState(new Declared());
}
driver.addScriptedElement(response);
return response;
}
use of org.apache.qpid.protonj2.types.Binary in project qpid-protonj2 by apache.
the class DeclareExpectation method declared.
/**
* Indicates a successful transaction declaration by returning a {@link Declared}
* disposition with the given transaction Id.
*
* @param txnId
* byte array containing the transaction id that has been declared.
*
* @return this {@link DispositionInjectAction} instance.
*/
public DispositionInjectAction declared(byte[] txnId) {
response = new DispositionInjectAction(driver);
response.withSettled(true);
if (txnId != null) {
response.withState(new Declared().setTxnId(new Binary(txnId)));
} else {
response.withState(new Declared());
}
driver.addScriptedElement(response);
return response;
}
use of org.apache.qpid.protonj2.types.Binary in project qpid-protonj2 by apache.
the class DataTypeEncoder method writeRawArray.
@Override
public void writeRawArray(ProtonBuffer buffer, EncoderState state, Object[] values) {
buffer.writeByte(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
state.getEncoder().writeUnsignedLong(buffer, state, getDescriptorCode());
buffer.writeByte(EncodingCodes.VBIN32);
for (Object value : values) {
final Binary binary = ((Data) value).getBinary();
buffer.writeInt(binary.getLength());
buffer.writeBytes(binary.getArray(), binary.getArrayOffset(), binary.getLength());
}
}
Aggregations