/workspaces/astro/sol3-sdk/cpp/sol3/core/any_message_output.h Source File

Space-ng SDK: /workspaces/astro/sol3-sdk/cpp/sol3/core/any_message_output.h Source File
Space-ng SDK
any_message_output.h
Go to the documentation of this file.
1 // Copyright (c) Space-ng, inc. All rights reserved.
2 #pragma once
3 
5 #include "sol3/core/msg/buffer.h"
6 #include "sol3/core/seq_ring.h"
8 #include "sol3/log/except.h"
9 
10 namespace sol3::core {
11 
18  public:
25  IBufferExchange& exchange,
28  size_t slot_count,
29  size_t slot_size);
30 
33 
36 
39 
41  MessagePort const& port() const { return port_; }
42 
43  flatbuffers::span<uint8_t const> headerSpan() const;
44 
45  flatbuffers::span<uint8_t const> payloadSpan() const;
46 
48  uint64_t write(
49  flatbuffers::span<uint8_t const> header_span,
50  flatbuffers::span<uint8_t const> payload_span);
51 
53 
54  template <typename TTableType>
55  TTableType const* payloadRoot() const {
56  if (payloadSpan().empty()) {
57  return nullptr;
58  }
59  return flatbuffers::GetSizePrefixedRoot<TTableType>(payloadSpan().data());
60  }
61 
62  MessageSchema schema() const { return schema_; }
63 
64  private:
65  uint64_t dataSize() const {
66  return SeqRingWriter::minDataSize(writer_.slotCount(), writer_.slotSize());
67  }
68  uint64_t trailerSize() { return output_buffer_->size() - dataSize(); }
69  uint8_t* trailerData();
70 
71  IBufferExchange& exchange_;
72  MessagePort port_;
73  MessageSchema schema_;
74  std::unique_ptr<IBufferMutable> output_buffer_;
75  SeqRingWriter writer_;
76  uint8_t const* last_header_data_ = nullptr;
77  uint8_t const* last_payload_data_ = nullptr;
78  size_t last_header_size_ = 0;
79  size_t last_payload_size_ = 0;
80 };
81 
82 } // namespace sol3::core
Definition: any_message_output.h:17
AnyMessageOutput(IBufferExchange &exchange, MessagePort port, MessageSchema schema, size_t slot_count, size_t slot_size)
~AnyMessageOutput()
Unregisters the output buffer from the exchange.
flatbuffers::span< uint8_t const > headerSpan() const
AnyMessageOutput(AnyMessageOutput const &)=delete
AnyMessageOutput & operator=(AnyMessageOutput &&rhs)=delete
AnyMessageOutput(AnyMessageOutput &&rhs)=delete
MessagePort const & port() const
Destination message port.
Definition: any_message_output.h:41
TTableType const * payloadRoot() const
Definition: any_message_output.h:55
uint64_t write(flatbuffers::span< uint8_t const > header_span, flatbuffers::span< uint8_t const > payload_span)
Returns the sequence number of the slot written to.
msg::MessageHeader const * headerRoot() const
flatbuffers::span< uint8_t const > payloadSpan() const
MessageSchema schema() const
Definition: any_message_output.h:62
AnyMessageOutput & operator=(AnyMessageOutput const &rhs)=delete
Interface for registering, discovering, and disposing shared buffers.
Definition: shmem_buffer.h:112
Definition: message_port.h:19
Definition: message_schema.h:12
static size_t minDataSize(size_t n_slots, size_t slot_size)
Minimum backing data size to hold n_slots of slot_size bytes.
size_t slotCount() const
Number of slots.
size_t slotSize() const
Size in bytes of each slot.
root_type MessageHeader
Definition: message_header.fbs:32
Definition: any_message_input.h:15