28#include <boost/move/make_unique.hpp>
42 flow::log::Log_context(config.m_logger_ptr,
Log_component::S_TRANSPORT),
44 m_segment_sz(config.m_segment_sz),
48 config.m_segment_sz, config.m_frame_prefix_sz, config.m_frame_postfix_sz))
50 FLOW_LOG_TRACE(
"Heap_fixed_builder [" << *
this <<
"]: Fixed-size builder started: "
59 FLOW_LOG_TRACE(
"Heap_fixed_builder [" << *
this <<
"]: Fixed-size builder being destroyed.");
67 assert(
m_engine &&
"Are you operating on a moved-from `*this`?");
77 if (flow::error::exec_void_and_throw_on_error
79 err_code,
"Heap_fixed_builder::emit_serialization()"))
85 assert(
m_engine &&
"Are you operating on a moved-from `*this`?");
93 size_t n_blobs = blob_ptrs.size();
94 m_engine->emit_segment_blobs(&blob_ptrs);
95 n_blobs = blob_ptrs.size() - n_blobs;
96 assert((n_blobs > 0) &&
"Empty serialization? What went wrong?");
98 for (
size_t abs_idx = blob_ptrs.size() - n_blobs, idx = 0;
102 const auto blob = blob_ptrs[abs_idx];
103 const auto seg_size = blob->size();
105 FLOW_LOG_TRACE(
"Heap_fixed_builder [" << *
this <<
"]: "
106 "Serialization segment [" << idx <<
"] (0 based, of [" << n_blobs <<
"], 1-based): "
107 "Heap buffer @[" <<
static_cast<const void*
>(blob->begin()) <<
"] sized [" << seg_size <<
"].");
112 FLOW_LOG_WARNING(
"Heap_fixed_builder [" << *
this <<
"]: "
113 "Serialization segment [" << idx <<
"] (0 based, of [" << n_blobs <<
"], 1-based): "
114 "Heap buffer @[" <<
static_cast<const void*
>(blob->begin()) <<
"] "
115 "sized [" << seg_size <<
"]: exceeded limit "
116 "[" <<
m_segment_sz <<
"]. Emitting error; will not return serialization.");
127 assert(
m_engine &&
"Are you operating on a moved-from `*this`?");
134 return os <<
'@' << &val;
140 flow::log::Log_context(config.m_logger_ptr,
Log_component::S_TRANSPORT)
142 FLOW_LOG_TRACE(
"Heap_reader [" << *
this <<
"]: Heap reader started: "
151 FLOW_LOG_TRACE(
"Heap_reader [" << *
this <<
"]: Reader being destroyed including: "
153 "no deserialization yet attempted.");
158 FLOW_LOG_TRACE(
"Heap_reader [" << *
this <<
"]: Reader being destroyed including: "
160 "last deserialization reports [" << (
m_engine->sizeInWords() *
sizeof(::capnp::word)) <<
"] "
161 "input heap space total.");
167 using flow::util::Blob;
169 const auto blob =
new Blob(get_logger(), max_sz);
172 FLOW_LOG_TRACE(
"Heap_reader [" << *
this <<
"]: "
175 "max-sized [" << max_sz <<
"].");
182 return os <<
'@' << &val;
192 return os << val.cStr();
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()
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.
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...
Heap_reader(const Config &config)
Implements concept API.
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.
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...
Small group of miscellaneous utilities to ease work with capnp (Cap'n Proto), joining its capnp names...
@ S_INTERNAL_ERROR_SERIALIZE_LEAF_TOO_BIG
Structured message serialization (e.g., when sending over channel): A user-mutated datum (e....
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,...
const Null_session NULL_SESSION
The only necessary value of empty-type Null_session.
std::ostream & operator<<(std::ostream &os, const Heap_fixed_builder &val)
Prints string representation of the given Heap_fixed_builder to the given ostream.
std::ostream & operator<<(std::ostream &os, const Bipc_mq_handle &val)
Prints string representation of the given Bipc_mq_handle to the given ostream.
boost::asio::const_buffer Blob_const
Short-hand for an immutable blob somewhere in memory, stored as exactly a void const * and a size_t.
Log_component
The flow::log::Component payload enumeration containing various log components used by Flow-IPC inter...
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
Implements Struct_builder::Config sub-concept.
Implements Struct_reader::Config sub-concept.
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...