Update for jart/json.cpp change

This commit is contained in:
Peter Johnson
2026-03-29 15:38:18 -07:00
parent de3e211fdb
commit 9ca93fa190
120 changed files with 1240 additions and 1087 deletions

View File

@@ -177,8 +177,8 @@ void HALSimWS::OnNetValueChanged(const wpi::util::json& msg) {
// generate the key
try {
auto& type = msg.at("type").get_ref<const std::string&>();
auto& device = msg.at("device").get_ref<const std::string&>();
auto& type = msg.at("type").get_string();
auto& device = msg.at("device").get_string();
wpi::util::SmallString<64> key;
key.append(type);
@@ -191,7 +191,7 @@ void HALSimWS::OnNetValueChanged(const wpi::util::json& msg) {
if (provider) {
provider->OnNetValueChanged(msg.at("data"));
}
} catch (wpi::util::json::exception& e) {
} catch (std::logic_error& e) {
wpi::util::print(stderr, "Error with incoming message: {}\n", e.what());
}
}

View File

@@ -48,18 +48,15 @@ void HALSimWSClientConnection::Initialize() {
return;
}
wpi::util::json j;
try {
j = wpi::util::json::parse(msg);
} catch (const wpi::util::json::parse_error& e) {
std::string err("JSON parse failed: ");
err += e.what();
auto j = wpi::util::json::parse(msg);
if (!j) {
auto err = fmt::format("JSON parse failed: {}", j.error());
wpi::util::print(stderr, "{}\n", err);
m_websocket->Fail(1003, err);
return;
}
m_client->OnNetValueChanged(j);
m_client->OnNetValueChanged(*j);
});
m_websocket->closed.connect([this](uint16_t, auto) {
@@ -79,11 +76,11 @@ void HALSimWSClientConnection::OnSimValueChanged(const wpi::util::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&>();
auto& type = msg.at("type").get_string();
if (!m_client->CanSendMessage(type)) {
return;
}
} catch (wpi::util::json::exception& e) {
} catch (std::logic_error& e) {
wpi::util::print(stderr, "Error with message: {}\n", e.what());
}

View File

@@ -16,7 +16,10 @@
#include "wpi/net/uv/Tcp.hpp"
#include "wpi/net/uv/Timer.hpp"
#include "wpi/util/StringMap.hpp"
#include "wpi/util/json_fwd.hpp"
namespace wpi::util {
class json;
} // namespace wpi::util
namespace wpilibws {

View File

@@ -12,8 +12,10 @@
#include "wpi/net/WebSocket.hpp"
#include "wpi/net/uv/Buffer.hpp"
#include "wpi/net/uv/Stream.hpp"
#include "wpi/util/json_fwd.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi::util {
class json;
} // namespace wpi::util
namespace wpilibws {