// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. #pragma once #include #include #include #include "frc/proto/VectorProto.h" #include "wpimath.pb.h" template google::protobuf::Message* wpi::Protobuf>::New( google::protobuf::Arena* arena) { return wpi::CreateMessage(arena); } template frc::Matrixd wpi::Protobuf>::Unpack( const google::protobuf::Message& msg) { auto m = static_cast(&msg); if (m->rows_size() != Size) { throw std::invalid_argument( fmt::format("Tried to unpack message with {} elements in rows into " "Vector with {} rows", m->rows_size(), Size)); } frc::Matrixd vec; for (int i = 0; i < Size; i++) { vec(i) = m->rows(i); } return vec; } template void wpi::Protobuf>::Pack( google::protobuf::Message* msg, const frc::Matrixd& value) { auto m = static_cast(msg); m->clear_rows(); for (int i = 0; i < Size; i++) { m->add_rows(value(i)); } }