31#include <flow/error/error.hpp>
32#include <boost/move/make_unique.hpp>
131 public flow::log::Log_context
300 boost::movelib::unique_ptr<Capnp_heap_engine>
m_engine;
325 public flow::log::Log_context,
326 private boost::noncopyable
401 template<
typename Struct>
459template<
typename Channel_obj,
typename Message_body>
461 =
Channel<Channel_obj, Message_body,
468template<
typename Struct>
471 using flow::error::Runtime_error;
472 using flow::util::buffers_dump_string;
473 using boost::movelib::make_unique;
476 using Capnp_word_array_array_ptr = kj::ArrayPtr<const Capnp_word_array_ptr>;
478 using Capnp_heap_engine_opts = ::capnp::ReaderOptions;
481 constexpr Capnp_heap_engine_opts RDR_OPTIONS = { std::numeric_limits<uint64_t>::max() /
sizeof(word),
482 Capnp_heap_engine_opts{}.nestingLimit };
485 const auto emit_error = [&](
const Error_code& our_err_code) -> Capnp_struct_reader
489 *err_code = our_err_code;
490 return Capnp_struct_reader();
493 throw Runtime_error(our_err_code,
"Heap_reader::deserialization()");
494 return Capnp_struct_reader();
503 assert((!
m_engine) &&
"Do not call deserialization() more than once.");
507 assert(
m_capnp_segments.empty() &&
"m_capnp_segments should have been empty so far, pre-deserialization().");
513 const auto data_ptr = serialization_segment->const_data();
514 const auto seg_size = serialization_segment->size();
516 if ((uintptr_t(data_ptr) %
sizeof(
void*)) != 0)
518 FLOW_LOG_WARNING(
"Heap_reader [" << *
this <<
"]: "
519 "Serialization segment [" << idx <<
"] "
521 "Heap buffer @[" <<
static_cast<const void*
>(data_ptr) <<
"] sized [" << seg_size <<
"]: "
522 "Starting pointer is not this-architecture-word-aligned. Bug? Misuse of Heap_reader? "
523 "Misalignment is against the API use requirements; capnp would complain and fail.");
528 FLOW_LOG_TRACE(
"Heap_reader [" << *
this <<
"]: "
529 "Serialization segment [" << idx <<
"] "
531 "Heap buffer @[" <<
static_cast<const void*
>(data_ptr) <<
"] sized [" << seg_size <<
"]: "
532 "Feeding into capnp deserialization engine.");
533 FLOW_LOG_DATA(
"Segment contents: "
534 "[\n" << buffers_dump_string(serialization_segment->const_buffer(),
" ") <<
"].");
536 capnp_segs.emplace_back(
reinterpret_cast<const word*
>(data_ptr),
537 seg_size /
sizeof(word));
546 const Capnp_word_array_array_ptr capnp_segs_ptr(&(capnp_segs.front()), capnp_segs.size());
547 m_engine = make_unique<Capnp_heap_engine>(capnp_segs_ptr, RDR_OPTIONS);
Owning and wrapping a pre-connected transport::Channel peer (an endpoint of an established channel ov...
A capnp::MessageBuilder used by Heap_fixed_builder: similar to a capnp::MallocMessageBuilder with the...
Implements Struct_builder concept by straightforwardly allocating fixed-size segments on-demand in th...
Capnp_msg_builder_interface * payload_msg_builder()
Implements concept API.
size_t n_serialization_segments() const
Implements concept API.
Heap_fixed_builder & operator=(Heap_fixed_builder &&src)
Implements concept API.
Heap_fixed_builder(const Heap_fixed_builder &)=delete
Disallow copy construction.
Heap_fixed_builder()
Implements concept API.
boost::movelib::unique_ptr< Capnp_heap_engine > m_engine
The capnp builder engine which really does the work including owning the needed allocated segments so...
void emit_serialization(Segment_ptrs *target_blobs, const Session &session, Error_code *err_code=0) const
Implements concept API.
~Heap_fixed_builder()
Implements concept API.
Heap_fixed_builder & operator=(const Heap_fixed_builder &)=delete
Disallow copy assignment.
Heap_fixed_builder(Heap_fixed_builder &&src)
Implements concept API.
size_t m_segment_sz
See ctor. We only store it to be able to emit S_INTERNAL_ERROR_SERIALIZE_LEAF_TOO_BIG in emit_seriali...
Implements Struct_reader concept by straightforwardly interpreting a serialization by Heap_fixed_buil...
Struct::Reader deserialization(Error_code *err_code=0)
Implements concept API.
Heap_reader(const Config &config)
Implements concept API.
boost::movelib::unique_ptr< Capnp_heap_engine > Capnp_heap_engine_ptr
Alias to pointer to Capnp_heap_engine.
std::vector< boost::movelib::unique_ptr< flow::util::Blob > > m_serialization_segments
The actual serialization supplied so far, as divided up into segments (Blobs – byte arrays).
~Heap_reader()
Implements concept API.
::capnp::SegmentArrayMessageReader Capnp_heap_engine
Alias for the capnp SegmentArrayMessageReader deserialization engine.
flow::util::Blob * add_serialization_segment(size_t max_sz)
Implements concept API.
Capnp_heap_engine_ptr m_engine
The capnp reader engine, as set in the deserialization() call and corresponding to the Struct::Reader...
std::vector< Capnp_word_array_ptr > m_capnp_segments
After deserialization(), capnp-targeted data structure which is essentially vector<> of each Blob::co...
kj::ArrayPtr< const ::capnp::word > Capnp_word_array_ptr
Alias to capnp type that's similar to boost::asio::const_buffer but stores word* and word count inste...
@ S_DESERIALIZE_FAILED_INSUFFICIENT_SEGMENTS
Structured message deserialization: Tried to deserialize without enough input segments (e....
@ S_DESERIALIZE_FAILED_SEGMENT_MISALIGNED
Structured message deserialization: An input segment is not aligned as required.
Reader< ipc::shm::classic::Pool_arena > Reader
Convenience alias: transport::struc::shm::Reader that works with boost.ipc.shm pools from ipc::shm::c...
Sub-module of Flow-IPC module ipc::transport providing transmission of structured messages specifical...
std::vector< flow::util::Blob * > Segment_ptrs
Sequence of 1+ Blob pointers to blobs which must stay alive while these pointers may be dereferenced,...
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
Implements Struct_builder::Config sub-concept.
flow::log::Logger * m_logger_ptr
Logger to use for logging subsequently.
size_t m_segment_sz
See struct doc header.
size_t m_frame_postfix_sz
See struct doc header.
size_t m_frame_prefix_sz
See struct doc header.
Implements Struct_reader::Config sub-concept.
flow::log::Logger * m_logger_ptr
Logger to use for logging subsequently.
size_t m_n_segments_est
Best guess for how many times you expect to call add_serialization_segment(); or 0 if you have no gue...
Value for Struct_builder::Session when no extra information is needed when serializing Struct_builder...