mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
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:
@@ -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>>()};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user