/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "photon/targeting/proto/PNPResultProto.h"
#include "photon.pb.h"
google::protobuf::Message* wpi::Protobuf::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<
photonvision::proto::ProtobufPNPResult>(arena);
}
photon::PNPResult wpi::Protobuf::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast(&msg);
if (!m->is_present()) {
return photon::PNPResult();
}
return photon::PNPResult{true,
wpi::UnpackProtobuf(m->best()),
m->best_reproj_err(),
wpi::UnpackProtobuf(m->alt()),
m->alt_reproj_err(),
m->ambiguity()};
}
void wpi::Protobuf::Pack(google::protobuf::Message* msg,
const photon::PNPResult& value) {
auto m = static_cast(msg);
m->set_is_present(value.isPresent);
wpi::PackProtobuf(m->mutable_best(), value.best);
m->set_best_reproj_err(value.bestReprojErr);
wpi::PackProtobuf(m->mutable_alt(), value.alt);
m->set_alt_reproj_err(value.altReprojErr);
m->set_ambiguity(value.ambiguity);
}