2023-11-21 13:11:57 -05:00
|
|
|
// 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.
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/math/geometry/proto/Translation2dProto.hpp"
|
2023-11-21 13:11:57 -05:00
|
|
|
|
2024-11-07 22:42:50 -08:00
|
|
|
#include "wpimath/protobuf/geometry2d.npb.h"
|
2024-06-28 09:28:39 -04:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
std::optional<wpi::math::Translation2d> wpi::util::Protobuf<wpi::math::Translation2d>::Unpack(
|
2024-11-07 22:42:50 -08:00
|
|
|
InputStream& stream) {
|
|
|
|
|
wpi_proto_ProtobufTranslation2d msg;
|
|
|
|
|
if (!stream.Decode(msg)) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
2023-11-21 13:11:57 -05:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
return wpi::math::Translation2d{
|
|
|
|
|
wpi::units::meter_t{msg.x},
|
|
|
|
|
wpi::units::meter_t{msg.y},
|
2023-11-21 13:11:57 -05:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
bool wpi::util::Protobuf<wpi::math::Translation2d>::Pack(OutputStream& stream,
|
|
|
|
|
const wpi::math::Translation2d& value) {
|
2024-11-07 22:42:50 -08:00
|
|
|
wpi_proto_ProtobufTranslation2d msg{
|
|
|
|
|
.x = value.X().value(),
|
|
|
|
|
.y = value.Y().value(),
|
|
|
|
|
};
|
|
|
|
|
return stream.Encode(msg);
|
2023-11-21 13:11:57 -05:00
|
|
|
}
|