[hal] WS Simulation: Add message filtering capability (#5395)

This commit is contained in:
Zhiquan Yeo
2023-06-20 11:26:03 -04:00
committed by GitHub
parent 0eccc3f247
commit c4dc697192
6 changed files with 105 additions and 1 deletions

View File

@@ -76,6 +76,16 @@ void HALSimHttpConnection::ProcessWsUpgrade() {
}
void HALSimHttpConnection::OnSimValueChanged(const wpi::json& msg) {
// Skip sending if this message is not in the allowed filter list
try {
auto& type = msg.at("type").get_ref<const std::string&>();
if (!m_server->CanSendMessage(type)) {
return;
}
} catch (wpi::json::exception& e) {
fmt::print(stderr, "Error with message: {}\n", e.what());
}
// render json to buffers
wpi::SmallVector<uv::Buffer, 4> sendBufs;
wpi::raw_uv_ostream os{sendBufs, [this]() -> uv::Buffer {