Ejemplo n.º 1
0
 void Send(const T& value) {
     if (self_verify_ && is_loopback_) {
         // for communication verification, send hash_code.
         size_t hash_code = typeid(T).hash_code();
         SyncSend(&hash_code, sizeof(hash_code));
     }
     if (std::is_pod<T>::value) {
         // send PODs directly from memory.
         SyncSend(&value, sizeof(value));
     }
     else if (data::Serialization<BufferBuilder, T>::is_fixed_size) {
         // fixed_size items can be sent without size header
         static constexpr size_t fixed_size
             = data::Serialization<BufferBuilder, T>::fixed_size;
         if (fixed_size < 2 * 1024 * 1024) {
             // allocate buffer on stack (no allocation)
             using FixedBuilder = FixedBufferBuilder<fixed_size>;
             FixedBuilder fb;
             data::Serialization<FixedBuilder, T>::Serialize(value, fb);
             assert(fb.size() == fixed_size);
             SyncSend(fb.data(), fb.size());
         }
         else {
             // too big, use heap allocation
             BufferBuilder bb;
             data::Serialization<BufferBuilder, T>::Serialize(value, bb);
             SyncSend(bb.data(), bb.size());
         }
     }
     else {
         // variable length items must be prefixed with size header
         BufferBuilder bb;
         data::Serialization<BufferBuilder, T>::Serialize(value, bb);
         size_t size = bb.size();
         SyncSend(&size, sizeof(size), MsgMore);
         SyncSend(bb.data(), bb.size());
     }
 }
Ejemplo n.º 2
0
 //! Constructor, assign memory area from BufferBuilder.
 explicit BufferRef(const BufferBuilder& bb)
     : data_(bb.data()), size_(bb.size())
 { }