1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/app/Message.hpp" 7 namespace hmbdc {
namespace tips {
namespace reliable {
8 template <
typename Buffer,
typename TransportMessageHeader,
typename AttachmentAllocator>
12 std::unique_ptr<uint8_t[]> hasMemoryAttachmentMessageWrapSpace_;
15 size_t attTrainCount_ = 0;
16 AttachmentAllocator alloc_;
19 hasMemoryAttachment_->release();
20 hasMemoryAttachment_ =
nullptr;
26 , hasMemoryAttachmentMessageWrapSpace_{
new uint8_t[maxItemSize()] {0}}
28 hasMemoryAttachmentMessageWrapSpace_.get())
31 size_t maxItemSize()
const {
32 return buffer_.maxItemSize();
34 void put(TransportMessageHeader* h) {
36 if (hmbdc_unlikely(h->typeTag() == app::StartMemorySegTrain::typeTag)) {
37 if (hmbdc_likely(!hasMemoryAttachment_)) {
39 *hasMemoryAttachment_ =
40 h->template wrapped<app::StartMemorySegTrain>().att;
41 attTrainCount_ = h->template wrapped<app::StartMemorySegTrain>().segCount;
42 alloc_(h->typeTag(), hasMemoryAttachment_);
44 hasMemoryAttachment_->len = 0;
47 }
else if (hmbdc_unlikely(hasMemoryAttachment_
48 && h->typeTag() == app::MemorySeg::typeTag)) {
50 auto seg = &h->template wrapped<app::MemorySeg>();
52 memcpy((
char*)hasMemoryAttachment_->attachment + hasMemoryAttachment_->len, seg, segLen);
53 hasMemoryAttachment_->len += segLen;
58 }
else if (hmbdc_unlikely(hasMemoryAttachment_)) {
59 if (hmbdc_likely(!attTrainCount_)
60 && h->flag == app::hasMemoryAttachment::flag) {
61 auto l = std::min<size_t>(buffer_.maxItemSize(), h->messagePayloadLen);
62 auto hsm = *hasMemoryAttachment_;
63 memcpy(hasMemoryAttachmentMessageWrapSpace_.get(), h->payload(), l);
64 *hasMemoryAttachment_ = hsm;
65 buffer_.putAtt(hasMemoryAttachmentMessageWrap_, buffer_.maxItemSize());
66 hasMemoryAttachment_ =
nullptr;
71 buffer_.put(h->payload(), h->messagePayloadLen);
76 template <
typename T>
void putSome(T& item) {
77 buffer_.put(&item, std::min(
sizeof(item), maxItemSize()));
Definition: AttBufferAdaptor.hpp:9
Definition: Message.hpp:212
Definition: Message.hpp:263
if a specific hmbdc network transport (for example tcpcast, rmcast, and rnetmap) supports message wit...
Definition: Message.hpp:125