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.
|
|
|
|
|
|
|
|
|
|
#include "frc/geometry/proto/Transform3dProto.h"
|
|
|
|
|
|
2024-11-07 22:42:50 -08:00
|
|
|
#include <wpi/protobuf/ProtobufCallbacks.h>
|
2024-06-28 09:28:39 -04:00
|
|
|
|
2024-11-07 22:42:50 -08:00
|
|
|
#include "wpimath/protobuf/geometry3d.npb.h"
|
2023-11-21 13:11:57 -05:00
|
|
|
|
2024-11-07 22:42:50 -08:00
|
|
|
std::optional<frc::Transform3d> wpi::Protobuf<frc::Transform3d>::Unpack(
|
|
|
|
|
InputStream& stream) {
|
|
|
|
|
wpi::UnpackCallback<frc::Translation3d> tsln;
|
|
|
|
|
wpi::UnpackCallback<frc::Rotation3d> rot;
|
|
|
|
|
wpi_proto_ProtobufTransform3d msg{
|
|
|
|
|
.translation = tsln.Callback(),
|
|
|
|
|
.rotation = rot.Callback(),
|
|
|
|
|
};
|
|
|
|
|
if (!stream.Decode(msg)) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto itsln = tsln.Items();
|
|
|
|
|
auto irot = rot.Items();
|
|
|
|
|
|
|
|
|
|
if (itsln.empty() || irot.empty()) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
2023-11-21 13:11:57 -05:00
|
|
|
|
|
|
|
|
return frc::Transform3d{
|
2024-11-07 22:42:50 -08:00
|
|
|
itsln[0],
|
|
|
|
|
irot[0],
|
2023-11-21 13:11:57 -05:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-07 22:42:50 -08:00
|
|
|
bool wpi::Protobuf<frc::Transform3d>::Pack(OutputStream& stream,
|
2023-11-21 13:11:57 -05:00
|
|
|
const frc::Transform3d& value) {
|
2024-11-07 22:42:50 -08:00
|
|
|
wpi::PackCallback tsln{&value.Translation()};
|
|
|
|
|
wpi::PackCallback rot{&value.Rotation()};
|
|
|
|
|
wpi_proto_ProtobufTransform3d msg{
|
|
|
|
|
.translation = tsln.Callback(),
|
|
|
|
|
.rotation = rot.Callback(),
|
|
|
|
|
};
|
|
|
|
|
return stream.Encode(msg);
|
2023-11-21 13:11:57 -05:00
|
|
|
}
|