common.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <cstring>
5 #include <optional>
6 #include <stdint.h>
7 #include <string>
8 #include <vector>
9 
10 namespace foxglove {
11 
12 constexpr char SUPPORTED_SUBPROTOCOL[] = "foxglove.websocket.v1";
13 constexpr char CAPABILITY_CLIENT_PUBLISH[] = "clientPublish";
14 constexpr char CAPABILITY_TIME[] = "time";
15 constexpr char CAPABILITY_PARAMETERS[] = "parameters";
16 constexpr char CAPABILITY_PARAMETERS_SUBSCRIBE[] = "parametersSubscribe";
17 constexpr char CAPABILITY_SERVICES[] = "services";
18 constexpr char CAPABILITY_CONNECTION_GRAPH[] = "connectionGraph";
19 constexpr char CAPABILITY_ASSETS[] = "assets";
20 
21 constexpr std::array<const char*, 6> DEFAULT_CAPABILITIES = {
24 };
25 
26 using ChannelId = uint32_t;
27 using ClientChannelId = uint32_t;
28 using SubscriptionId = uint32_t;
29 using ServiceId = uint32_t;
30 
31 enum class BinaryOpcode : uint8_t {
32  MESSAGE_DATA = 1,
33  TIME_DATA = 2,
36 };
37 
38 enum class ClientBinaryOpcode : uint8_t {
39  MESSAGE_DATA = 1,
41 };
42 
43 enum class WebSocketLogLevel {
44  Debug,
45  Info,
46  Warn,
47  Error,
48  Critical,
49 };
50 
52  std::string topic;
53  std::string encoding;
54  std::string schemaName;
55  std::string schema;
56  std::optional<std::string> schemaEncoding;
57 
58  bool operator==(const ChannelWithoutId& other) const {
59  return topic == other.topic && encoding == other.encoding && schemaName == other.schemaName &&
60  schema == other.schema && schemaEncoding == other.schemaEncoding;
61  }
62 };
63 
66 
67  Channel() = default; // requirement for json conversions.
69  : ChannelWithoutId(std::move(ch))
70  , id(id) {}
71 
72  bool operator==(const Channel& other) const {
73  return id == other.id && ChannelWithoutId::operator==(other);
74  }
75 };
76 
79  std::string topic;
80  std::string encoding;
81  std::string schemaName;
82  std::vector<uint8_t> schema;
83 };
84 
85 struct ClientMessage {
86  uint64_t logTime;
87  uint64_t publishTime;
88  uint32_t sequence;
90  size_t dataLength;
91  std::vector<uint8_t> data;
92 
93  ClientMessage(uint64_t logTime, uint64_t publishTime, uint32_t sequence,
94  const ClientAdvertisement& advertisement, size_t dataLength, const uint8_t* rawData)
95  : logTime(logTime)
100  , data(dataLength) {
101  std::memcpy(data.data(), rawData, dataLength);
102  }
103 
104  static const size_t MSG_PAYLOAD_OFFSET = 5;
105 
106  const uint8_t* getData() const {
107  return data.data() + MSG_PAYLOAD_OFFSET;
108  }
109  std::size_t getLength() const {
110  return data.size() - MSG_PAYLOAD_OFFSET;
111  }
112 };
113 
115  std::string name;
116  std::string type;
117  std::string requestSchema;
118  std::string responseSchema;
119 };
120 
123 
124  Service() = default;
125  Service(const ServiceWithoutId& s, const ServiceId& id)
127  , id(id) {}
128 };
129 
132  uint32_t callId;
133  std::string encoding;
134  std::vector<uint8_t> data;
135 
136  size_t size() const {
137  return 4 + 4 + 4 + encoding.size() + data.size();
138  }
139  void read(const uint8_t* data, size_t size);
140  void write(uint8_t* data) const;
141 
142  bool operator==(const ServiceResponse& other) const {
143  return serviceId == other.serviceId && callId == other.callId && encoding == other.encoding &&
144  data == other.data;
145  }
146 };
147 
149 
150 enum class FetchAssetStatus : uint8_t {
151  Success = 0,
152  Error = 1,
153 };
154 
156  uint32_t requestId;
158  std::string errorMessage;
159  std::vector<uint8_t> data;
160 };
161 
162 } // namespace foxglove
foxglove::ClientMessage::ClientMessage
ClientMessage(uint64_t logTime, uint64_t publishTime, uint32_t sequence, const ClientAdvertisement &advertisement, size_t dataLength, const uint8_t *rawData)
Definition: common.hpp:93
foxglove::BinaryOpcode::FETCH_ASSET_RESPONSE
@ FETCH_ASSET_RESPONSE
foxglove::WebSocketLogLevel::Warn
@ Warn
foxglove::FetchAssetResponse::data
std::vector< uint8_t > data
Definition: common.hpp:159
foxglove::ChannelWithoutId::encoding
std::string encoding
Definition: common.hpp:53
foxglove::Service::id
ServiceId id
Definition: common.hpp:122
foxglove
Definition: base64.hpp:8
foxglove::ServiceResponse::operator==
bool operator==(const ServiceResponse &other) const
Definition: common.hpp:142
foxglove::ClientAdvertisement::topic
std::string topic
Definition: common.hpp:79
foxglove::Service::Service
Service()=default
foxglove::Channel
Definition: common.hpp:64
foxglove::BinaryOpcode::MESSAGE_DATA
@ MESSAGE_DATA
foxglove::ChannelWithoutId::operator==
bool operator==(const ChannelWithoutId &other) const
Definition: common.hpp:58
foxglove::WebSocketLogLevel::Error
@ Error
foxglove::ClientChannelId
uint32_t ClientChannelId
Definition: common.hpp:27
foxglove::ClientBinaryOpcode::SERVICE_CALL_REQUEST
@ SERVICE_CALL_REQUEST
foxglove::ServiceResponse::encoding
std::string encoding
Definition: common.hpp:133
s
XmlRpcServer s
foxglove::ServiceResponse
Definition: common.hpp:130
foxglove::BinaryOpcode::SERVICE_CALL_RESPONSE
@ SERVICE_CALL_RESPONSE
foxglove::ServiceWithoutId::responseSchema
std::string responseSchema
Definition: common.hpp:118
foxglove::CAPABILITY_CLIENT_PUBLISH
constexpr char CAPABILITY_CLIENT_PUBLISH[]
Definition: common.hpp:13
foxglove::ServiceWithoutId
Definition: common.hpp:114
foxglove::ServiceResponse::callId
uint32_t callId
Definition: common.hpp:132
foxglove::FetchAssetResponse
Definition: common.hpp:155
foxglove::CAPABILITY_TIME
constexpr char CAPABILITY_TIME[]
Definition: common.hpp:14
foxglove::Channel::id
ChannelId id
Definition: common.hpp:65
foxglove::ServiceResponse::size
size_t size() const
Definition: common.hpp:136
foxglove::ChannelWithoutId::topic
std::string topic
Definition: common.hpp:52
foxglove::ServiceWithoutId::name
std::string name
Definition: common.hpp:115
foxglove::ServiceResponse::data
std::vector< uint8_t > data
Definition: common.hpp:134
foxglove::Service::Service
Service(const ServiceWithoutId &s, const ServiceId &id)
Definition: common.hpp:125
foxglove::BinaryOpcode::TIME_DATA
@ TIME_DATA
foxglove::ServiceWithoutId::type
std::string type
Definition: common.hpp:116
foxglove::SUPPORTED_SUBPROTOCOL
constexpr char SUPPORTED_SUBPROTOCOL[]
Definition: common.hpp:12
foxglove::WebSocketLogLevel::Info
@ Info
foxglove::CAPABILITY_PARAMETERS_SUBSCRIBE
constexpr char CAPABILITY_PARAMETERS_SUBSCRIBE[]
Definition: common.hpp:16
foxglove::ClientAdvertisement::channelId
ClientChannelId channelId
Definition: common.hpp:78
foxglove::WebSocketLogLevel
WebSocketLogLevel
Definition: common.hpp:43
foxglove::DEFAULT_CAPABILITIES
constexpr std::array< const char *, 6 > DEFAULT_CAPABILITIES
Definition: common.hpp:21
foxglove::ClientMessage::advertisement
ClientAdvertisement advertisement
Definition: common.hpp:89
foxglove::WebSocketLogLevel::Debug
@ Debug
foxglove::ClientAdvertisement
Definition: common.hpp:77
foxglove::ClientMessage::getData
const uint8_t * getData() const
Definition: common.hpp:106
foxglove::ClientMessage
Definition: common.hpp:85
foxglove::ServiceResponse::serviceId
ServiceId serviceId
Definition: common.hpp:131
foxglove::Channel::Channel
Channel(ChannelId id, ChannelWithoutId ch)
Definition: common.hpp:68
foxglove::ClientAdvertisement::schema
std::vector< uint8_t > schema
Definition: common.hpp:82
foxglove::SubscriptionId
uint32_t SubscriptionId
Definition: common.hpp:28
foxglove::ChannelWithoutId
Definition: common.hpp:51
foxglove::ClientMessage::logTime
uint64_t logTime
Definition: common.hpp:86
foxglove::ChannelWithoutId::schema
std::string schema
Definition: common.hpp:55
foxglove::FetchAssetResponse::errorMessage
std::string errorMessage
Definition: common.hpp:158
foxglove::ServiceWithoutId::requestSchema
std::string requestSchema
Definition: common.hpp:117
foxglove::ClientBinaryOpcode::MESSAGE_DATA
@ MESSAGE_DATA
foxglove::ClientAdvertisement::encoding
std::string encoding
Definition: common.hpp:80
foxglove::CAPABILITY_PARAMETERS
constexpr char CAPABILITY_PARAMETERS[]
Definition: common.hpp:15
foxglove::ClientAdvertisement::schemaName
std::string schemaName
Definition: common.hpp:81
foxglove::ClientMessage::sequence
uint32_t sequence
Definition: common.hpp:88
foxglove::ClientBinaryOpcode
ClientBinaryOpcode
Definition: common.hpp:38
std
foxglove::FetchAssetResponse::status
FetchAssetStatus status
Definition: common.hpp:157
foxglove::Channel::operator==
bool operator==(const Channel &other) const
Definition: common.hpp:72
foxglove::ClientMessage::publishTime
uint64_t publishTime
Definition: common.hpp:87
foxglove::ChannelId
uint32_t ChannelId
Definition: common.hpp:26
foxglove::BinaryOpcode
BinaryOpcode
Definition: common.hpp:31
foxglove::FetchAssetStatus::Error
@ Error
foxglove::ChannelWithoutId::schemaEncoding
std::optional< std::string > schemaEncoding
Definition: common.hpp:56
foxglove::CAPABILITY_SERVICES
constexpr char CAPABILITY_SERVICES[]
Definition: common.hpp:17
foxglove::WebSocketLogLevel::Critical
@ Critical
foxglove::CAPABILITY_ASSETS
constexpr char CAPABILITY_ASSETS[]
Definition: common.hpp:19
foxglove::ServiceResponse::write
void write(uint8_t *data) const
Definition: serialization.cpp:158
foxglove::FetchAssetStatus
FetchAssetStatus
Definition: common.hpp:150
foxglove::ClientMessage::dataLength
size_t dataLength
Definition: common.hpp:90
foxglove::ChannelWithoutId::schemaName
std::string schemaName
Definition: common.hpp:54
foxglove::Channel::Channel
Channel()=default
foxglove::ClientMessage::data
std::vector< uint8_t > data
Definition: common.hpp:91
foxglove::ServiceId
uint32_t ServiceId
Definition: common.hpp:29
foxglove::FetchAssetStatus::Success
@ Success
foxglove::CAPABILITY_CONNECTION_GRAPH
constexpr char CAPABILITY_CONNECTION_GRAPH[]
Definition: common.hpp:18
foxglove::ClientMessage::getLength
std::size_t getLength() const
Definition: common.hpp:109
foxglove::ClientMessage::MSG_PAYLOAD_OFFSET
static const size_t MSG_PAYLOAD_OFFSET
Definition: common.hpp:104
foxglove::ServiceResponse::read
void read(const uint8_t *data, size_t size)
Definition: serialization.cpp:143
foxglove::FetchAssetResponse::requestId
uint32_t requestId
Definition: common.hpp:156
foxglove::Service
Definition: common.hpp:121


foxglove_bridge
Author(s): Foxglove
autogenerated on Wed Mar 5 2025 03:34:31