001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.math.geometry.proto;
006
007import edu.wpi.first.math.geometry.Rotation3d;
008import edu.wpi.first.math.geometry.Transform3d;
009import edu.wpi.first.math.geometry.Translation3d;
010import edu.wpi.first.math.proto.Geometry3D.ProtobufTransform3d;
011import edu.wpi.first.util.protobuf.Protobuf;
012import us.hebi.quickbuf.Descriptors.Descriptor;
013
014public class Transform3dProto implements Protobuf<Transform3d, ProtobufTransform3d> {
015  @Override
016  public Class<Transform3d> getTypeClass() {
017    return Transform3d.class;
018  }
019
020  @Override
021  public Descriptor getDescriptor() {
022    return ProtobufTransform3d.getDescriptor();
023  }
024
025  @Override
026  public Protobuf<?, ?>[] getNested() {
027    return new Protobuf<?, ?>[] {Translation3d.proto, Rotation3d.proto};
028  }
029
030  @Override
031  public ProtobufTransform3d createMessage() {
032    return ProtobufTransform3d.newInstance();
033  }
034
035  @Override
036  public Transform3d unpack(ProtobufTransform3d msg) {
037    return new Transform3d(
038        Translation3d.proto.unpack(msg.getTranslation()),
039        Rotation3d.proto.unpack(msg.getRotation()));
040  }
041
042  @Override
043  public void pack(ProtobufTransform3d msg, Transform3d value) {
044    Translation3d.proto.pack(msg.getMutableTranslation(), value.getTranslation());
045    Rotation3d.proto.pack(msg.getMutableRotation(), value.getRotation());
046  }
047}