Skip to content

Commit

Permalink
parse json with GetCharBuffer (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansen4857 authored Nov 10, 2023
1 parent 023aa80 commit 116341a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,7 @@ frc2::CommandPtr AutoBuilder::buildAuto(std::string autoName) {
throw std::runtime_error("Cannot open file: " + filePath);
}

// Workaround to trim trailing \0 bytes
std::span<const uint8_t> buffer = fileBuffer->GetBuffer();
size_t trimSize = buffer.size();
for (size_t i = trimSize - 1; i != 0; i--) {
if (buffer[i] == 0) {
trimSize = i;
} else {
break;
}
}
std::span<const uint8_t> trimmed = buffer.first(trimSize);

wpi::json json = wpi::json::parse(trimmed.begin(), trimmed.end());
wpi::json json = wpi::json::parse(fileBuffer->GetCharBuffer());

return getAutoCommandFromJson(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,7 @@ std::shared_ptr<PathPlannerPath> PathPlannerPath::fromPathFile(
throw std::runtime_error("Cannot open file: " + filePath);
}

// Workaround to trim trailing \0 bytes
std::span<const uint8_t> buffer = fileBuffer->GetBuffer();
size_t trimSize = buffer.size();
for (size_t i = trimSize - 1; i != 0; i--) {
if (buffer[i] == 0) {
trimSize = i;
} else {
break;
}
}
std::span<const uint8_t> trimmed = buffer.first(trimSize);

wpi::json json = wpi::json::parse(trimmed.begin(), trimmed.end());
wpi::json json = wpi::json::parse(fileBuffer->GetCharBuffer());

std::shared_ptr < PathPlannerPath > path = std::make_shared
< PathPlannerPath > (PathPlannerPath::fromJson(json));
Expand Down

0 comments on commit 116341a

Please sign in to comment.