use of org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection in project qpid-broker-j by apache.
the class Message_1_0 method getContent.
@Override
public QpidByteBuffer getContent(final int offset, final int length) {
if (getMessageMetaData().getVersion() == 0) {
SectionDecoder sectionDecoder = new SectionDecoderImpl(DESCRIBED_TYPE_REGISTRY.getSectionDecoderRegistry());
try {
List<EncodingRetainingSection<?>> sections;
// not just #getSize()
try (QpidByteBuffer allSectionsContent = super.getContent(0, Integer.MAX_VALUE)) {
sections = sectionDecoder.parseAll(allSectionsContent);
}
List<QpidByteBuffer> bodySectionContent = new ArrayList<>();
for (final EncodingRetainingSection<?> section : sections) {
if (section instanceof DataSection || section instanceof AmqpValueSection || section instanceof AmqpSequenceSection) {
bodySectionContent.add(section.getEncodedForm());
}
section.dispose();
}
try (QpidByteBuffer bodyContent = QpidByteBuffer.concatenate(bodySectionContent)) {
bodySectionContent.forEach(QpidByteBuffer::dispose);
return bodyContent.view(offset, length);
}
} catch (AmqpErrorException e) {
throw new ConnectionScopedRuntimeException(e);
}
} else {
return super.getContent(offset, length);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection in project qpid-broker-j by apache.
the class MessageDecoder method parse.
public void parse() throws AmqpErrorException {
if (!_parsed) {
List<EncodingRetainingSection<?>> sections;
try (QpidByteBuffer combined = QpidByteBuffer.concatenate(_fragments)) {
sections = _sectionDecoder.parseAll(combined);
}
_fragments.forEach(QpidByteBuffer::dispose);
Iterator<EncodingRetainingSection<?>> iter = sections.iterator();
EncodingRetainingSection<?> s = iter.hasNext() ? iter.next() : null;
if (s instanceof HeaderSection) {
_headerSection = (HeaderSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof DeliveryAnnotationsSection) {
_deliveryAnnotationsSection = (DeliveryAnnotationsSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof MessageAnnotationsSection) {
_messageAnnotationsSection = (MessageAnnotationsSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof PropertiesSection) {
_propertiesSection = (PropertiesSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof ApplicationPropertiesSection) {
_applicationPropertiesSection = (ApplicationPropertiesSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof AmqpValueSection) {
_contentSize = s.getEncodedSize();
_dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} else if (s instanceof DataSection) {
do {
_contentSize += s.getEncodedSize();
_dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} while (s instanceof DataSection);
} else if (s instanceof AmqpSequenceSection) {
do {
_contentSize += s.getEncodedSize();
_dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} while (s instanceof AmqpSequenceSection);
} else {
throw new IllegalStateException("Application data sections are not found");
}
if (s instanceof FooterSection) {
_footerSection = (FooterSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s != null) {
throw new IllegalStateException(String.format("Encountered unexpected section '%s'", s.getClass().getSimpleName()));
}
_parsed = true;
}
}
Aggregations