mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpiutil] Return wpi::expected from MemoryBuffer::GetFile (#7069)
This commit is contained in:
@@ -28,14 +28,12 @@ void TrajectoryUtil::ToPathweaverJson(const Trajectory& trajectory,
|
||||
}
|
||||
|
||||
Trajectory TrajectoryUtil::FromPathweaverJson(std::string_view path) {
|
||||
std::error_code ec;
|
||||
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
|
||||
wpi::MemoryBuffer::GetFile(path, ec);
|
||||
if (fileBuffer == nullptr || ec) {
|
||||
auto fileBuffer = wpi::MemoryBuffer::GetFile(path);
|
||||
if (!fileBuffer) {
|
||||
throw std::runtime_error(fmt::format("Cannot open file: {}", path));
|
||||
}
|
||||
|
||||
wpi::json json = wpi::json::parse(fileBuffer->GetCharBuffer());
|
||||
wpi::json json = wpi::json::parse(fileBuffer.value()->GetCharBuffer());
|
||||
|
||||
return Trajectory{json.get<std::vector<Trajectory::State>>()};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user