OGLplus  (0.59.0) a C++ wrapper for rendering APIs

message.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_MESSAGE_HPP
10 #define EAGINE_MESSAGE_BUS_MESSAGE_HPP
11 
12 #include "../assert.hpp"
13 #include "../bitfield.hpp"
14 #include "../callable_ref.hpp"
15 #include "../main_ctx_fwd.hpp"
16 #include "../memory/buffer_pool.hpp"
17 #include "../memory/copy.hpp"
18 #include "../memory/span_algo.hpp"
19 #include "../message_id.hpp"
20 #include "../reflect/map_enumerators.hpp"
21 #include "../serialize/size_and_data.hpp"
22 #include "context_fwd.hpp"
23 #include "types.hpp"
24 #include "verification.hpp"
25 #include <chrono>
26 #include <cstdint>
27 #include <limits>
28 #include <vector>
29 
30 namespace eagine::msgbus {
31 //------------------------------------------------------------------------------
32 #define EAGINE_MSGBUS_ID(METHOD) EAGINE_MSG_ID(eagiMsgBus, METHOD)
33 //------------------------------------------------------------------------------
36 static constexpr auto is_special_message(message_id msg_id) noexcept {
37  return msg_id.has_class(EAGINE_ID(eagiMsgBus));
38 }
39 //------------------------------------------------------------------------------
42 static constexpr auto broadcast_endpoint_id() noexcept -> identifier_t {
43  return 0U;
44 }
45 //------------------------------------------------------------------------------
49 using message_timestamp = std::chrono::steady_clock::time_point;
50 //------------------------------------------------------------------------------
54 using message_age = std::chrono::duration<float>;
55 //------------------------------------------------------------------------------
58 enum class message_priority : std::uint8_t {
60  idle,
62  low,
64  normal,
66  high,
68  critical
69 };
70 //------------------------------------------------------------------------------
74 static inline auto operator<(message_priority l, message_priority r) noexcept
75  -> bool {
76  using U = std::underlying_type_t<message_priority>;
77  return U(l) < U(r);
78 }
79 //------------------------------------------------------------------------------
80 template <typename Selector>
81 constexpr auto
82 enumerator_mapping(type_identity<message_priority>, Selector) noexcept {
83  return enumerator_map_type<message_priority, 5>{
84  {{"critical", message_priority::critical},
85  {"high", message_priority::high},
86  {"normal", message_priority::normal},
87  {"low", message_priority::low},
88  {"idle", message_priority::idle}}};
89 }
90 //------------------------------------------------------------------------------
94 enum class message_crypto_flag : std::uint8_t {
96  asymmetric = 1U << 0U,
98  signed_header = 1U << 1U,
100  signed_content = 1U << 2U
101 };
105 //------------------------------------------------------------------------------
106 template <typename Selector>
107 constexpr auto
108 enumerator_mapping(type_identity<message_crypto_flag>, Selector) noexcept {
109  return enumerator_map_type<message_crypto_flag, 3>{
110  {{"asymmetric", message_crypto_flag::asymmetric},
111  {"signed_header", message_crypto_flag::signed_header},
112  {"signed_content", message_crypto_flag::signed_content}}};
113 }
114 //------------------------------------------------------------------------------
119 struct message_info {
120  static constexpr auto invalid_id() noexcept -> identifier_t {
121  return 0U;
122  }
123 
128 
133 
138 
142 
146 
148  using hop_count_t = std::int8_t;
149 
155 
157  using age_t = std::int8_t;
158 
165 
169 
172 
173  auto assign(const message_info& that) noexcept -> auto& {
174  return *this = that;
175  }
176 
180  auto too_many_hops() const noexcept -> bool {
181  return hop_count >= hop_count_t(64);
182  }
183 
187  auto add_hop() noexcept -> auto& {
188  EAGINE_ASSERT(hop_count < std::numeric_limits<hop_count_t>::max());
189  ++hop_count;
190  return *this;
191  }
192 
196  auto too_old() const noexcept -> bool {
197  switch(priority) {
199  return age_quarter_seconds > 10 * 4;
201  return age_quarter_seconds > 20 * 4;
203  return age_quarter_seconds > 30 * 4;
205  return age_quarter_seconds == std::numeric_limits<age_t>::max();
207  break;
208  }
209  return false;
210  }
211 
215  auto add_age(message_age age) noexcept -> auto& {
216  const float added_quarter_seconds = (age.count() + 0.20F) * 4.F;
217  if(auto new_age{convert_if_fits<age_t>(
218  int(age_quarter_seconds) + int(added_quarter_seconds))}) {
219  age_quarter_seconds = extract(new_age);
220  } else {
221  age_quarter_seconds = std::numeric_limits<age_t>::max();
222  }
223  return *this;
224  }
225 
229  auto age() const noexcept -> message_age {
230  return message_age{float(age_quarter_seconds) * 0.25F};
231  }
232 
234  auto set_priority(message_priority new_priority) noexcept -> auto& {
235  priority = new_priority;
236  return *this;
237  }
238 
240  auto set_source_id(identifier_t id) noexcept -> auto& {
241  source_id = id;
242  return *this;
243  }
244 
246  auto set_target_id(identifier_t id) noexcept -> auto& {
247  target_id = id;
248  return *this;
249  }
250 
254  auto has_serializer_id(identifier id) const noexcept -> bool {
255  return serializer_id == id.value();
256  }
257 
261  auto set_serializer_id(identifier id) noexcept -> auto& {
262  serializer_id = id.value();
263  return *this;
264  }
265 
268  auto set_sequence_no(message_sequence_t no) noexcept -> auto& {
269  sequence_no = no;
270  return *this;
271  }
272 
277  auto setup_response(const message_info& info) noexcept -> auto& {
278  target_id = info.source_id;
279  sequence_no = info.sequence_no;
280  age_quarter_seconds = info.age_quarter_seconds;
281  priority = info.priority;
282  return *this;
283  }
284 };
285 //------------------------------------------------------------------------------
289 
292 
294  constexpr message_view() noexcept = default;
295 
297  constexpr message_view(memory::const_block init) noexcept
298  : data{init} {}
299 
301  constexpr message_view(memory::block init) noexcept
302  : data{init} {}
303 
305  constexpr message_view(string_view init) noexcept
306  : data{as_bytes(init)} {}
307 
309  constexpr message_view(message_info info, memory::const_block init) noexcept
310  : message_info{info}
311  , data{init} {}
312 };
313 //------------------------------------------------------------------------------
316 class stored_message : public message_info {
317 public:
319  stored_message() = default;
320 
325  , _buffer{std::move(buf)} {
326  memory::copy_into(view(message.data), _buffer);
327  }
328 
330  operator message_view() const {
331  return {*this, data()};
332  }
333 
335  template <typename Source>
336  void fetch_all_from(Source& source) {
337  _buffer.clear();
338  source.fetch_all(_buffer);
339  }
340 
343  memory::copy_into(blk, _buffer);
344  }
345 
346  template <typename Backend, typename Value>
347  auto do_store_value(const Value& value, span_size_t max_size) -> bool;
348 
350  template <typename Value>
351  auto store_value(const Value& value, span_size_t max_size) -> bool;
352 
353  template <typename Backend, typename Value>
354  auto do_fetch_value(Value& value) -> bool;
355 
357  template <typename Value>
358  auto fetch_value(Value& value) -> bool;
359 
361  auto storage() noexcept -> memory::block {
362  return cover(_buffer);
363  }
364 
366  auto data() const noexcept -> memory::const_block {
367  return view(_buffer);
368  }
369 
372  auto is_signed() const noexcept -> bool {
375  }
376 
380  auto signature() const noexcept -> memory::const_block {
381  if(is_signed()) {
382  return skip(data(), skip_data_with_size(data()));
383  }
384  return {};
385  }
386 
389  auto content() noexcept -> memory::block {
390  if(EAGINE_UNLIKELY(is_signed())) {
391  return get_data_with_size(storage());
392  }
393  return storage();
394  }
395 
399  auto content() const noexcept -> memory::const_block {
400  if(EAGINE_UNLIKELY(is_signed())) {
401  return get_data_with_size(data());
402  }
403  return data();
404  }
405 
408  auto text_content() noexcept {
409  return as_chars(content());
410  }
411 
414  auto text_content() const noexcept {
415  return as_chars(content());
416  }
417 
419  void clear_data() noexcept {
420  _buffer.clear();
421  }
422 
424  auto release_buffer() noexcept -> memory::buffer {
425  return std::move(_buffer);
426  }
427 
429  auto store_and_sign(
431  span_size_t max_size,
432  context&,
433  main_ctx_object&) -> bool;
434 
436  auto verify_bits(context&, main_ctx_object&) const noexcept
438 
439 private:
440  memory::buffer _buffer{};
441 };
442 //------------------------------------------------------------------------------
447 public:
450  _messages.reserve(64);
451  }
452 
454  auto empty() const noexcept -> bool {
455  return _messages.empty();
456  }
457 
459  auto count() const noexcept -> span_size_t {
460  return span_size(_messages.size());
461  }
462 
464  void push(message_id msg_id, const message_view& message) {
465  _messages.emplace_back(
466  msg_id,
467  stored_message{message, _buffers.get(message.data.size())},
468  _clock_t::now());
469  }
470 
474  template <typename Function>
475  auto push_if(Function function, span_size_t req_size = 0) -> bool {
476  _messages.emplace_back(
477  message_id{},
478  stored_message{{}, _buffers.get(req_size)},
479  _clock_t::now());
480  auto& [msg_id, message, insert_time] = _messages.back();
481  EAGINE_MAYBE_UNUSED(insert_time);
482  bool rollback = false;
483  try {
484  if(!function(msg_id, insert_time, message)) {
485  rollback = true;
486  }
487  } catch(...) {
488  rollback = true;
489  }
490  if(rollback) {
491  _buffers.eat(message.release_buffer());
492  _messages.pop_back();
493  return false;
494  }
495  return true;
496  }
497 
503  using fetch_handler =
505 
507  auto fetch_all(fetch_handler handler) -> bool;
508 
514 
516  void cleanup(cleanup_predicate predicate);
517 
518 private:
519  using _clock_t = std::chrono::steady_clock;
520  memory::buffer_pool _buffers;
521  std::vector<std::tuple<message_id, stored_message, message_timestamp>>
522  _messages;
523 };
524 //------------------------------------------------------------------------------
525 class message_pack_info {
526 public:
527  using bit_set = std::uint64_t;
528 
529  message_pack_info(span_size_t total_size) noexcept
530  : _total_size{limit_cast<std::uint16_t>(total_size)} {}
531 
532  auto is_empty() const noexcept {
533  return _packed_bits == 0U;
534  }
535 
536  auto bits() const noexcept -> bit_set {
537  return _packed_bits;
538  }
539 
540  auto count() const noexcept -> span_size_t {
541  span_size_t result = 0;
542  auto bits = _packed_bits;
543  while(bits) {
544  ++result;
545  bits &= (bits - 1U);
546  }
547  return result;
548  }
549 
550  auto used() const noexcept -> span_size_t {
551  return span_size(_packed_size);
552  }
553 
554  auto total() const noexcept -> span_size_t {
555  return span_size(_total_size);
556  }
557 
558  auto usage() const noexcept {
559  return float(used()) / float(total());
560  }
561 
562  void add(span_size_t msg_size, bit_set current_bit) noexcept {
563  _packed_size += limit_cast<std::uint16_t>(msg_size);
564  _packed_bits |= current_bit;
565  }
566 
567 private:
568  bit_set _packed_bits{0U};
569  std::uint16_t _packed_size{0};
570  const std::uint16_t _total_size{0};
571 };
572 //------------------------------------------------------------------------------
573 class serialized_message_storage {
574 public:
577  using fetch_handler =
579 
580  serialized_message_storage() {
581  _messages.reserve(32);
582  }
583 
584  auto empty() const noexcept -> bool {
585  return _messages.empty();
586  }
587 
588  auto count() const noexcept -> span_size_t {
589  return span_size(_messages.size());
590  }
591 
592  auto top() const noexcept -> memory::const_block {
593  if(!_messages.empty()) {
594  return view(std::get<0>(_messages.front()));
595  }
596  return {};
597  }
598 
599  void pop() noexcept {
600  EAGINE_ASSERT(!_messages.empty());
601  _buffers.eat(std::move(std::get<0>(_messages.front())));
602  _messages.erase(_messages.begin());
603  }
604 
605  void push(memory::const_block message) {
606  EAGINE_ASSERT(!message.empty());
607  auto buf = _buffers.get(message.size());
608  memory::copy_into(message, buf);
609  _messages.emplace_back(std::move(buf), _clock_t::now());
610  }
611 
612  auto fetch_all(fetch_handler handler) -> bool;
613 
614  auto pack_into(memory::block dest) -> message_pack_info;
615 
616  void cleanup(const message_pack_info& to_be_removed);
617 
618 private:
619  using _clock_t = std::chrono::steady_clock;
620  memory::buffer_pool _buffers;
621  std::vector<std::tuple<memory::buffer, message_timestamp>> _messages;
622 };
623 //------------------------------------------------------------------------------
624 class endpoint;
625 //------------------------------------------------------------------------------
626 class message_context {
627 public:
628  message_context(endpoint& ep) noexcept
629  : _bus{ep} {}
630 
631  constexpr message_context(endpoint& ep, message_id mi) noexcept
632  : _bus{ep}
633  , _msg_id{std::move(mi)} {}
634 
635  auto bus() const noexcept -> endpoint& {
636  return _bus;
637  }
638 
639  auto msg_id() const noexcept -> const message_id& {
640  return _msg_id;
641  }
642 
643  auto set_msg_id(message_id msg_id) noexcept -> message_context& {
644  _msg_id = std::move(msg_id);
645  return *this;
646  }
647 
648 private:
649  endpoint& _bus;
650  message_id _msg_id{};
651 };
652 //------------------------------------------------------------------------------
653 class message_priority_queue {
654 public:
655  using handler_type =
656  callable_ref<bool(const message_context&, stored_message&)>;
657 
658  message_priority_queue() {
659  _messages.reserve(128);
660  }
661 
662  auto size() const noexcept {
663  return _messages.size();
664  }
665 
666  auto push(const message_view& message) -> stored_message& {
667  auto pos = std::lower_bound(
668  _messages.begin(),
669  _messages.end(),
670  message.priority,
671  [](auto& msg, auto pri) { return msg.priority < pri; });
672 
673  return *_messages.emplace(
674  pos, message, _buffers.get(message.data.size()));
675  }
676 
677  auto process_one(const message_context& msg_ctx, handler_type handler)
678  -> bool {
679  if(!_messages.empty()) {
680  if(handler(msg_ctx, _messages.back())) {
681  _buffers.eat(_messages.back().release_buffer());
682  _messages.pop_back();
683  return true;
684  }
685  }
686  return false;
687  }
688 
689  auto process_all(const message_context& msg_ctx, handler_type handler)
690  -> span_size_t {
691  span_size_t count{0};
692  std::size_t pos = 0;
693  while(pos < _messages.size()) {
694  if(handler(msg_ctx, _messages[pos])) {
695  ++count;
696  _buffers.eat(_messages[pos].release_buffer());
697  _messages.erase(_messages.begin() + pos);
698  } else {
699  ++pos;
700  }
701  }
702  return count;
703  }
704 
705 private:
706  memory::buffer_pool _buffers;
707  std::vector<stored_message> _messages;
708 };
709 //------------------------------------------------------------------------------
710 class connection_outgoing_messages {
711 public:
712  auto count() const noexcept -> span_size_t {
713  return _serialized.count();
714  }
715 
716  auto enqueue(
717  main_ctx_object& user,
718  message_id,
719  const message_view&,
720  memory::block) -> bool;
721 
722  auto pack_into(memory::block dest) -> message_pack_info {
723  return _serialized.pack_into(dest);
724  }
725 
726  void cleanup(const message_pack_info& packed) {
727  _serialized.cleanup(packed);
728  }
729 
730 private:
731  serialized_message_storage _serialized{};
732 };
733 //------------------------------------------------------------------------------
734 class connection_incoming_messages {
735 public:
736  using fetch_handler =
737  callable_ref<bool(message_id, message_age, const message_view&)>;
738 
739  auto empty() const noexcept -> bool {
740  return _packed.empty();
741  }
742 
743  auto count() const noexcept -> span_size_t {
744  return _packed.count();
745  }
746 
747  void push(memory::const_block data) {
748  _packed.push(data);
749  }
750 
751  auto fetch_messages(main_ctx_object& user, fetch_handler handler) -> bool;
752 
753 private:
754  serialized_message_storage _packed{};
755  message_storage _unpacked{};
756 };
757 //------------------------------------------------------------------------------
758 } // namespace eagine::msgbus
759 
760 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
761 #include <eagine/message_bus/message.inl>
762 #endif
763 
764 #endif // EAGINE_MESSAGE_BUS_MESSAGE_HPP
auto push_if(Function function, span_size_t req_size=0) -> bool
Pushes a new message and lets a function to fill it.
Definition: message.hpp:475
message_sequence_t sequence_t
Alias for the sequence number type.
Definition: message.hpp:141
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
@ high
High, sent before messages with lower priority.
Declaration of class template storing a reference to a callable object.
Definition: callable_ref.hpp:24
@ idle
Idle, sent only when no messages with higher priority are enqueued.
static constexpr auto as_bytes(basic_span< T, P, S > spn) noexcept -> basic_block< std::is_const_v< T >>
Converts a span into a basic_block.
Definition: block.hpp:39
#define EAGINE_ID(NAME)
Macro for constructing instances of eagine::identifier.
Definition: identifier.hpp:353
static constexpr auto span_size(T v) noexcept
Converts argument to span size type.
Definition: types.hpp:59
static auto copy_into(const_block source, buffer &dest) -> block
Copies the content of source block to destination buffer.
Definition: copy.hpp:33
Base class for main context objects.
Definition: main_ctx_object.hpp:71
bitfield< verification_bit > verification_bits
Alias for a bus message verification bitfield.
Definition: verification.hpp:47
auto content() noexcept -> memory::block
Returns a mutable view of the data content of the message.
Definition: message.hpp:389
static constexpr auto is_special_message(message_id msg_id) noexcept
Indicates if the specified message id denotes a special message bus message.
Definition: message.hpp:36
auto fetch_all(fetch_handler handler) -> bool
Fetches all currently stored messages and calls handler on them.
auto data() const noexcept -> memory::const_block
Returns a const view of the storage buffer.
Definition: message.hpp:366
auto store_value(const Value &value, span_size_t max_size) -> bool
Serializes and stores the specified value (up to max_size).
Definition: serialize.hpp:293
auto fetch_value(Value &value) -> bool
Deserializes the stored content into the specified value.
Definition: serialize.hpp:306
constexpr message_view() noexcept=default
Default constructor.
Structure storing information about a sigle message bus message.
Definition: message.hpp:119
static constexpr auto cover(T *addr, S size) noexcept -> span_if_mutable< T >
Creates a span starting at the specified pointer and specified length.
Definition: span.hpp:465
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
auto age() const noexcept -> message_age
Returns the message age.
Definition: message.hpp:229
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
auto set_serializer_id(identifier id) noexcept -> auto &
Sets the id of the used data content serializer.
Definition: message.hpp:261
@ info
Informational log entries.
constexpr auto has(bit_type bit) const noexcept
Tests if the specified bit is set.
Definition: bitfield.hpp:70
std::chrono::steady_clock::time_point message_timestamp
Alias for message timestamp type.
Definition: message.hpp:49
static constexpr auto view(T *addr, S size) noexcept -> const_span< T >
Creates a view starting at the specified pointer and specified length.
Definition: span.hpp:458
@ endpoint
Message bus client endpoint.
hop_count_t hop_count
The message hop counter.
Definition: message.hpp:154
basic_callable_ref< Sig, is_noexcept_function_v< Sig > > callable_ref
Alias for callable object references.
Definition: callable_ref.hpp:191
Class storing multiple reusable memory buffer instances.
Definition: buffer_pool.hpp:21
auto get(span_size_t req_size=0) -> memory::buffer
Gets a buffer with the specified required size.
Definition: buffer_pool.hpp:26
basic_block< false > block
Alias for non-const byte memory span.
Definition: block.hpp:27
identifier_t source_id
Returns the source endpoint identifier.
Definition: message.hpp:127
auto verify_bits(context &, main_ctx_object &) const noexcept -> verification_bits
Verifies the signatures of this message.
memory::const_block data
View of the message data content.
Definition: message.hpp:291
void fetch_all_from(Source &source)
Copies the remaining data from the specified serialization source.
Definition: message.hpp:336
Class holding common message bus utility objects.
Definition: context.hpp:37
auto setup_response(const message_info &info) noexcept -> auto &
Sets the target id to be the source id from info, copies sequence number.
Definition: message.hpp:277
identifier_t target_id
Returns the target endpoint identifier.
Definition: message.hpp:132
identifier_t serializer_id
Returns the identifier of the used serializer.
Definition: message.hpp:137
stored_message(message_view message, memory::buffer buf) noexcept
Construction from a message view and storage buffer. Adopts the buffer and copies the content from th...
Definition: message.hpp:323
static constexpr auto broadcast_endpoint_id() noexcept -> identifier_t
Returns the special broadcase message bus endpoint id.
Definition: message.hpp:42
auto empty() const noexcept -> bool
Indicates if the storage is empty.
Definition: message.hpp:454
@ signed_content
The message content is signed.
sequence_t sequence_no
The message sequence number.
Definition: message.hpp:145
constexpr message_view(memory::block init) noexcept
Construction from a mutable memory block.
Definition: message.hpp:301
@ signed_header
The message header is signed.
auto count() const noexcept -> span_size_t
Returns the coung of messages in the storage.
Definition: message.hpp:459
message_storage()
Default constructor.
Definition: message.hpp:449
Reallocatable owning byte buffer.
Definition: buffer.hpp:22
void cleanup(cleanup_predicate predicate)
Removes messages based on the result of the specified predicate.
Combines message information and a non-owning view to message content.
Definition: message.hpp:288
auto has_serializer_id(identifier id) const noexcept -> bool
Tests if a data serializer with the specified id was used.
Definition: message.hpp:254
std::uint32_t message_sequence_t
Alias for message sequence number type.
Definition: types.hpp:22
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
message_crypto_flag
Message cryptography-related flag bits enumeration.
Definition: message.hpp:94
static constexpr auto skip(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Skips a specified count of elements from the front of a span.
Definition: span_algo.hpp:60
auto content() const noexcept -> memory::const_block
Returns a const view of the data content of the message.
Definition: message.hpp:399
callable_ref< bool(message_id, message_age, const message_view &)> fetch_handler
Alias for the message fetch handler.
Definition: message.hpp:504
auto clear() -> auto &
Clears the buffer.
Definition: buffer.hpp:149
@ critical
Critical, sent as soon as possible.
message_priority
Message priority enumeration.
Definition: message.hpp:58
void eat(memory::buffer used)
Returns the specified buffer back to the pool for further reuse.
Definition: buffer_pool.hpp:44
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
@ normal
Normal, default message priority.
auto signature() const noexcept -> memory::const_block
Returns the message signature.
Definition: message.hpp:380
auto set_sequence_no(message_sequence_t no) noexcept -> auto &
Sets the sequence number of this message (has message-type specific meaning).
Definition: message.hpp:268
auto storage() noexcept -> memory::block
Returns a mutable view of the storage buffer.
Definition: message.hpp:361
stored_message()=default
Default constructor.
auto set_target_id(identifier_t id) noexcept -> auto &
Sets the target endpoint identifier.
Definition: message.hpp:246
constexpr message_view(string_view init) noexcept
Construction from a string view.
Definition: message.hpp:305
auto add_hop() noexcept -> auto &
Increments the hop counter.
Definition: message.hpp:187
message_crypto_flags crypto_flags
The message cryptography flags.
Definition: message.hpp:171
Class storing message bus messages.
Definition: message.hpp:446
void clear_data() noexcept
Clears the content of the storage buffer.
Definition: message.hpp:419
static auto get_data_with_size(memory::block src) noexcept -> memory::block
Extracts a sub-block from a larger mutable block with encoded sub-block size.
Definition: size_and_data.hpp:62
auto is_signed() const noexcept -> bool
Indicates if the header or the content is signed.
Definition: message.hpp:372
std::uint64_t identifier_t
The underlying integer type for eagine::identifier.
Definition: identifier_t.hpp:19
static auto skip_data_with_size(memory::const_block src) noexcept -> span_size_t
In a block starting with sub-block with size returns the size of the sub-block.
Definition: size_and_data.hpp:50
void push(message_id msg_id, const message_view &message)
Pushes a message into this storage.
Definition: message.hpp:464
Template type used mostly for function type-tag dispatching.
Definition: type_identity.hpp:19
auto store_and_sign(memory::const_block data, span_size_t max_size, context &, main_ctx_object &) -> bool
Stores the specified data and signs it.
Class storing two identifier values representing class/method pair.
Definition: message_id.hpp:25
auto text_content() const noexcept
Returns the content as a const string view.
Definition: message.hpp:414
auto set_source_id(identifier_t id) noexcept -> auto &
Sets the source endpoint identifier.
Definition: message.hpp:240
message_priority priority
The message priority.
Definition: message.hpp:168
auto add_age(message_age age) noexcept -> auto &
Adds to the age seconds counter.
Definition: message.hpp:215
constexpr message_view(message_info info, memory::const_block init) noexcept
Construction from a message info and a const memory block.
Definition: message.hpp:309
@ low
Low message priority.
Combines message information and an owned message content buffer.
Definition: message.hpp:316
std::int8_t age_t
Alias for type used to store the message age in quarter seconds.
Definition: message.hpp:157
@ asymmetric
Assymetric cipher is used (symmetric otherwise).
static constexpr auto as_chars(block blk) noexcept
Converts a block into a span of characters.
Definition: block.hpp:48
auto too_many_hops() const noexcept -> bool
Indicates that the message made too many hops.
Definition: message.hpp:180
static constexpr auto operator<(const valid_if< T, P1 > &v1, const valid_if< T, P2 > &v2) noexcept -> tribool
Less-than comparison of two conditionally valid values.
Definition: decl.hpp:180
auto set_priority(message_priority new_priority) noexcept -> auto &
Sets the priority of this message.
Definition: message.hpp:234
auto release_buffer() noexcept -> memory::buffer
Releases and returns the storage buffer (without clearing it).
Definition: message.hpp:424
@ message_id
The message type id has been verified.
std::int8_t hop_count_t
Alias for type used to store the message hop count.
Definition: message.hpp:148
auto too_old() const noexcept -> bool
Indicates that the message is too old.
Definition: message.hpp:196
auto text_content() noexcept
Returns the content as a mutable string view.
Definition: message.hpp:408
std::chrono::duration< float > message_age
Alias for message age type.
Definition: message.hpp:54
age_t age_quarter_seconds
The message age in quarter seconds.
Definition: message.hpp:164
void store_content(memory::const_block blk)
Copies the content from the given block into the internal buffer.
Definition: message.hpp:342

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).