mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
Use char instead of uint8_t for json::parse (#5877)
The uint8_t usage causes warnings on newer clang versions. Add GetCharBuffer() to MemoryBuffer classes to make this easy.
This commit is contained in:
@@ -22,7 +22,7 @@ AprilTagFieldLayout::AprilTagFieldLayout(std::string_view path) {
|
|||||||
throw std::runtime_error(fmt::format("Cannot open file: {}", path));
|
throw std::runtime_error(fmt::format("Cannot open file: {}", path));
|
||||||
}
|
}
|
||||||
|
|
||||||
wpi::json json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end());
|
wpi::json json = wpi::json::parse(fileBuffer->GetCharBuffer());
|
||||||
|
|
||||||
for (const auto& tag : json.at("tags").get<std::vector<AprilTag>>()) {
|
for (const auto& tag : json.at("tags").get<std::vector<AprilTag>>()) {
|
||||||
m_apriltags[tag.ID] = tag;
|
m_apriltags[tag.ID] = tag;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ bool ReadConfig() {
|
|||||||
// parse file
|
// parse file
|
||||||
wpi::json j;
|
wpi::json j;
|
||||||
try {
|
try {
|
||||||
j = wpi::json::parse(fileBuffer->begin(), fileBuffer->end());
|
j = wpi::json::parse(fileBuffer->GetCharBuffer());
|
||||||
} catch (const wpi::json::parse_error& e) {
|
} catch (const wpi::json::parse_error& e) {
|
||||||
fmt::print(stderr, "config error in '{}': byte {}: {}\n", configFile,
|
fmt::print(stderr, "config error in '{}': byte {}: {}\n", configFile,
|
||||||
e.byte, e.what());
|
e.byte, e.what());
|
||||||
|
|||||||
@@ -137,9 +137,8 @@ static bool LoadWindowStorageImpl(const std::string& filename) {
|
|||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
return JsonToWindow(
|
return JsonToWindow(wpi::json::parse(fileBuffer->GetCharBuffer()),
|
||||||
wpi::json::parse(fileBuffer->begin(), fileBuffer->end()),
|
filename.c_str());
|
||||||
filename.c_str());
|
|
||||||
} catch (wpi::json::parse_error& e) {
|
} catch (wpi::json::parse_error& e) {
|
||||||
ImGui::LogText("Error loading %s: %s", filename.c_str(), e.what());
|
ImGui::LogText("Error loading %s: %s", filename.c_str(), e.what());
|
||||||
return false;
|
return false;
|
||||||
@@ -164,9 +163,8 @@ static bool LoadStorageRootImpl(Context* ctx, const std::string& filename,
|
|||||||
createdStorage = true;
|
createdStorage = true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
storage->FromJson(
|
storage->FromJson(wpi::json::parse(fileBuffer->GetCharBuffer()),
|
||||||
wpi::json::parse(fileBuffer->begin(), fileBuffer->end()),
|
filename.c_str());
|
||||||
filename.c_str());
|
|
||||||
} catch (wpi::json::parse_error& e) {
|
} catch (wpi::json::parse_error& e) {
|
||||||
ImGui::LogText("Error loading %s: %s", filename.c_str(), e.what());
|
ImGui::LogText("Error loading %s: %s", filename.c_str(), e.what());
|
||||||
if (createdStorage) {
|
if (createdStorage) {
|
||||||
|
|||||||
@@ -457,7 +457,7 @@ AnalysisManager::AnalysisManager(std::string_view path, Settings& settings,
|
|||||||
throw FileReadingError(path);
|
throw FileReadingError(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end());
|
m_json = wpi::json::parse(fileBuffer->GetCharBuffer());
|
||||||
|
|
||||||
WPI_INFO(m_logger, "Read {}", path);
|
WPI_INFO(m_logger, "Read {}", path);
|
||||||
}
|
}
|
||||||
@@ -475,7 +475,7 @@ AnalysisManager::AnalysisManager(std::string_view path, Settings& settings,
|
|||||||
throw FileReadingError(newPath);
|
throw FileReadingError(newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end());
|
m_json = wpi::json::parse(fileBuffer->GetCharBuffer());
|
||||||
|
|
||||||
WPI_INFO(m_logger, "Read {}", newPath);
|
WPI_INFO(m_logger, "Read {}", newPath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ static wpi::json GetJSON(std::string_view path, wpi::Logger& logger) {
|
|||||||
throw std::runtime_error(fmt::format("Unable to read: {}", path));
|
throw std::runtime_error(fmt::format("Unable to read: {}", path));
|
||||||
}
|
}
|
||||||
|
|
||||||
wpi::json json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end());
|
wpi::json json = wpi::json::parse(fileBuffer->GetCharBuffer());
|
||||||
WPI_INFO(logger, "Read frc-characterization JSON from {}", path);
|
WPI_INFO(logger, "Read frc-characterization JSON from {}", path);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ Trajectory TrajectoryUtil::FromPathweaverJson(std::string_view path) {
|
|||||||
throw std::runtime_error(fmt::format("Cannot open file: {}", path));
|
throw std::runtime_error(fmt::format("Cannot open file: {}", path));
|
||||||
}
|
}
|
||||||
|
|
||||||
wpi::json json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end());
|
wpi::json json = wpi::json::parse(fileBuffer->GetCharBuffer());
|
||||||
|
|
||||||
return Trajectory{json.get<std::vector<Trajectory::State>>()};
|
return Trajectory{json.get<std::vector<Trajectory::State>>()};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ class MemoryBuffer {
|
|||||||
|
|
||||||
std::span<const uint8_t> GetBuffer() const { return {begin(), end()}; }
|
std::span<const uint8_t> GetBuffer() const { return {begin(), end()}; }
|
||||||
|
|
||||||
|
std::span<const char> GetCharBuffer() const {
|
||||||
|
return {reinterpret_cast<const char*>(begin()),
|
||||||
|
reinterpret_cast<const char*>(end())};
|
||||||
|
}
|
||||||
|
|
||||||
/// Return an identifier for this buffer, typically the filename it was read
|
/// Return an identifier for this buffer, typically the filename it was read
|
||||||
/// from.
|
/// from.
|
||||||
virtual std::string_view GetBufferIdentifier() const {
|
virtual std::string_view GetBufferIdentifier() const {
|
||||||
@@ -145,6 +150,10 @@ class WritableMemoryBuffer : public MemoryBuffer {
|
|||||||
uint8_t* begin() { return const_cast<uint8_t*>(MemoryBuffer::begin()); }
|
uint8_t* begin() { return const_cast<uint8_t*>(MemoryBuffer::begin()); }
|
||||||
uint8_t* end() { return const_cast<uint8_t*>(MemoryBuffer::end()); }
|
uint8_t* end() { return const_cast<uint8_t*>(MemoryBuffer::end()); }
|
||||||
std::span<uint8_t> GetBuffer() { return {begin(), end()}; }
|
std::span<uint8_t> GetBuffer() { return {begin(), end()}; }
|
||||||
|
std::span<char> GetCharBuffer() const {
|
||||||
|
return {reinterpret_cast<char*>(const_cast<uint8_t*>(begin())),
|
||||||
|
reinterpret_cast<char*>(const_cast<uint8_t*>(end()))};
|
||||||
|
}
|
||||||
|
|
||||||
static std::unique_ptr<WritableMemoryBuffer> GetFile(
|
static std::unique_ptr<WritableMemoryBuffer> GetFile(
|
||||||
std::string_view filename, std::error_code& ec, int64_t fileSize = -1);
|
std::string_view filename, std::error_code& ec, int64_t fileSize = -1);
|
||||||
@@ -196,6 +205,10 @@ class WriteThroughMemoryBuffer : public MemoryBuffer {
|
|||||||
uint8_t* begin() { return const_cast<uint8_t*>(MemoryBuffer::begin()); }
|
uint8_t* begin() { return const_cast<uint8_t*>(MemoryBuffer::begin()); }
|
||||||
uint8_t* end() { return const_cast<uint8_t*>(MemoryBuffer::end()); }
|
uint8_t* end() { return const_cast<uint8_t*>(MemoryBuffer::end()); }
|
||||||
std::span<uint8_t> GetBuffer() { return {begin(), end()}; }
|
std::span<uint8_t> GetBuffer() { return {begin(), end()}; }
|
||||||
|
std::span<char> GetCharBuffer() const {
|
||||||
|
return {reinterpret_cast<char*>(const_cast<uint8_t*>(begin())),
|
||||||
|
reinterpret_cast<char*>(const_cast<uint8_t*>(end()))};
|
||||||
|
}
|
||||||
|
|
||||||
static std::unique_ptr<WriteThroughMemoryBuffer> GetFile(
|
static std::unique_ptr<WriteThroughMemoryBuffer> GetFile(
|
||||||
std::string_view filename, std::error_code& ec, int64_t fileSize = -1);
|
std::string_view filename, std::error_code& ec, int64_t fileSize = -1);
|
||||||
|
|||||||
Reference in New Issue
Block a user