Replace wpi::raw_istream with wpi::MemoryBuffer (#5675)

Instances of wpi::raw_istream were left that are reading incrementally
from file descriptors like USB devices.
This commit is contained in:
Tyler Veness
2023-09-21 23:20:09 -07:00
committed by GitHub
parent 1b6ec5a95d
commit 5ab54ff760
7 changed files with 51 additions and 56 deletions

View File

@@ -7,9 +7,9 @@
#include <system_error>
#include <fmt/format.h>
#include <wpi/MemoryBuffer.h>
#include <wpi/SmallString.h>
#include <wpi/json.h>
#include <wpi/raw_istream.h>
#include <wpi/raw_ostream.h>
using namespace frc;
@@ -29,15 +29,14 @@ void TrajectoryUtil::ToPathweaverJson(const Trajectory& trajectory,
}
Trajectory TrajectoryUtil::FromPathweaverJson(std::string_view path) {
std::error_code error_code;
wpi::raw_fd_istream input{path, error_code};
if (error_code) {
std::error_code ec;
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
wpi::MemoryBuffer::GetFile(path, ec);
if (fileBuffer == nullptr || ec) {
throw std::runtime_error(fmt::format("Cannot open file: {}", path));
}
wpi::json json;
input >> json;
wpi::json json = wpi::json::parse({fileBuffer->begin(), fileBuffer->end()});
return Trajectory{json.get<std::vector<Trajectory::State>>()};
}