Skip to content

Commit 194cec9

Browse files
authored
Fix cpp compiler warnings (#797)
### Changelog None ### Docs None ### Description - include websocketpp & nlohman_json as system libs to suppress compiler warnings - fix conversion warning - fix declaration hides class member warning
1 parent 58af014 commit 194cec9

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

cpp/foxglove-websocket/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ find_package(nlohmann_json REQUIRED)
55
find_package(websocketpp REQUIRED)
66

77
add_library(foxglove_websocket src/base64.cpp src/parameter.cpp src/serialization.cpp src/server_factory.cpp)
8-
target_include_directories(foxglove_websocket PUBLIC include)
8+
target_include_directories(foxglove_websocket
9+
PUBLIC include
10+
SYSTEM
11+
${nlohmann_json_INCLUDE_DIRS}
12+
${websocketpp_INCLUDE_DIRS}
13+
)
914
target_link_libraries(foxglove_websocket nlohmann_json::nlohmann_json websocketpp::websocketpp)
1015
set_target_properties(foxglove_websocket PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
1116

cpp/foxglove-websocket/include/foxglove/websocket/common.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ struct ServiceResponse {
148148
size_t size() const {
149149
return 4 + 4 + 4 + encoding.size() + data.size();
150150
}
151-
void read(const uint8_t* data, size_t size);
152-
void write(uint8_t* data) const;
151+
void read(const uint8_t* payload, size_t payloadSize);
152+
void write(uint8_t* payload) const;
153153

154154
bool operator==(const ServiceResponse& other) const {
155155
return serviceId == other.serviceId && callId == other.callId && encoding == other.encoding &&

cpp/foxglove-websocket/include/foxglove/websocket/websocket_server.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ inline void Server<ServerConfiguration>::sendFetchAssetResponse(
15361536
const uint8_t status = static_cast<uint8_t>(response.status);
15371537
message->append_payload(&status, 1);
15381538

1539-
foxglove::WriteUint32LE(uint32Data.data(), response.errorMessage.size());
1539+
foxglove::WriteUint32LE(uint32Data.data(), static_cast<uint32_t>(response.errorMessage.size()));
15401540
message->append_payload(uint32Data.data(), uint32Data.size());
15411541
message->append_payload(response.errorMessage.data(), errMsgSize);
15421542

cpp/foxglove-websocket/src/serialization.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,32 +157,32 @@ void from_json(const nlohmann::json& j, ServiceRequestDefinition& r) {
157157
r.schema = j["schema"].get<std::string>();
158158
}
159159

160-
void ServiceResponse::read(const uint8_t* data, size_t dataLength) {
160+
void ServiceResponse::read(const uint8_t* payload, size_t payloadSize) {
161161
size_t offset = 0;
162-
this->serviceId = ReadUint32LE(data + offset);
162+
this->serviceId = ReadUint32LE(payload + offset);
163163
offset += 4;
164-
this->callId = ReadUint32LE(data + offset);
164+
this->callId = ReadUint32LE(payload + offset);
165165
offset += 4;
166-
const size_t encondingLength = static_cast<size_t>(ReadUint32LE(data + offset));
166+
const size_t encondingLength = static_cast<size_t>(ReadUint32LE(payload + offset));
167167
offset += 4;
168-
this->encoding = std::string(reinterpret_cast<const char*>(data + offset), encondingLength);
168+
this->encoding = std::string(reinterpret_cast<const char*>(payload + offset), encondingLength);
169169
offset += encondingLength;
170-
const auto payloadLength = dataLength - offset;
171-
this->data.resize(payloadLength);
172-
std::memcpy(this->data.data(), data + offset, payloadLength);
170+
const auto dataSize = payloadSize - offset;
171+
this->data.resize(dataSize);
172+
std::memcpy(this->data.data(), payload + offset, dataSize);
173173
}
174174

175-
void ServiceResponse::write(uint8_t* data) const {
175+
void ServiceResponse::write(uint8_t* payload) const {
176176
size_t offset = 0;
177-
foxglove::WriteUint32LE(data + offset, this->serviceId);
177+
foxglove::WriteUint32LE(payload + offset, this->serviceId);
178178
offset += 4;
179-
foxglove::WriteUint32LE(data + offset, this->callId);
179+
foxglove::WriteUint32LE(payload + offset, this->callId);
180180
offset += 4;
181-
foxglove::WriteUint32LE(data + offset, static_cast<uint32_t>(this->encoding.size()));
181+
foxglove::WriteUint32LE(payload + offset, static_cast<uint32_t>(this->encoding.size()));
182182
offset += 4;
183-
std::memcpy(data + offset, this->encoding.data(), this->encoding.size());
183+
std::memcpy(payload + offset, this->encoding.data(), this->encoding.size());
184184
offset += this->encoding.size();
185-
std::memcpy(data + offset, this->data.data(), this->data.size());
185+
std::memcpy(payload + offset, this->data.data(), this->data.size());
186186
}
187187

188188
} // namespace foxglove

0 commit comments

Comments
 (0)