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

Space-ng SDK: /workspaces/astro/sol3-sdk/cpp/sol3/core/message_port.h Source File
Space-ng SDK
message_port.h
Go to the documentation of this file.
1 // Copyright (c) Space-ng, inc. All rights reserved.
2 #pragma once
3 #include "sol3/core/msg/message_header.h"
4 
5 namespace sol3::core {
6 
19 class MessagePort {
20  public:
22  MessagePort() = default;
23 
25  MessagePort(uint32_t encoded, uint32_t payload_type)
26  : encoded_(encoded), payload_type_(payload_type) {}
27 
33  uint32_t component_id,
34  msg::InterfaceType interface_type,
35  uint32_t interface_id,
36  uint32_t payload_type)
37  : encoded_(
38  ((component_id & 0x0fffu) << 16) |
39  ((interface_type & 0x000fu) << 12) | (interface_id & 0x0fffu)),
40  payload_type_(payload_type) {}
42  uint16_t componentId() const { return (encoded_ >> 16) & 0x0fff; }
43 
46  return static_cast<sol3::core::msg::InterfaceType>(
47  (encoded_ >> 12) & 0x000fu);
48  }
50  uint16_t interfaceId() const { return encoded_ & 0x0fff; }
51 
53  uint32_t payloadType() const { return payload_type_; }
54 
56  uint32_t encoded() const { return encoded_; }
57 
58  private:
59  uint32_t encoded_{};
60  uint32_t payload_type_{};
61 };
62 std::string format_as(MessagePort const& port);
63 } // namespace sol3::core
Definition: message_port.h:19
sol3::core::msg::InterfaceType interfaceType() const
Interface type encoded in bits [15:12].
Definition: message_port.h:45
uint16_t componentId() const
12-bit component identifier extracted from the port value.
Definition: message_port.h:42
uint32_t encoded() const
Packed 32-bit port value.
Definition: message_port.h:56
MessagePort(uint32_t encoded, uint32_t payload_type)
Construct from encoded value.
Definition: message_port.h:25
MessagePort()=default
Default-constructed port with zero value and payload type.
uint16_t interfaceId() const
12-bit interface/index extracted from the port value.
Definition: message_port.h:50
MessagePort(uint32_t component_id, msg::InterfaceType interface_type, uint32_t interface_id, uint32_t payload_type)
Definition: message_port.h:32
uint32_t payloadType() const
32-bit FlatBuffers file identifier of the payload type for this port.
Definition: message_port.h:53
InterfaceType
Definition: message_header.fbs:5
Definition: any_message_input.h:15
std::string format_as(AnyMessageView &view)
Definition: any_message_view.h:111