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.kinematics.proto;
006
007import edu.wpi.first.math.geometry.Translation2d;
008import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
009import edu.wpi.first.math.proto.Kinematics.ProtobufMecanumDriveKinematics;
010import edu.wpi.first.util.protobuf.Protobuf;
011import us.hebi.quickbuf.Descriptors.Descriptor;
012
013public class MecanumDriveKinematicsProto
014    implements Protobuf<MecanumDriveKinematics, ProtobufMecanumDriveKinematics> {
015  @Override
016  public Class<MecanumDriveKinematics> getTypeClass() {
017    return MecanumDriveKinematics.class;
018  }
019
020  @Override
021  public Descriptor getDescriptor() {
022    return ProtobufMecanumDriveKinematics.getDescriptor();
023  }
024
025  @Override
026  public Protobuf<?, ?>[] getNested() {
027    return new Protobuf<?, ?>[] {Translation2d.proto};
028  }
029
030  @Override
031  public ProtobufMecanumDriveKinematics createMessage() {
032    return ProtobufMecanumDriveKinematics.newInstance();
033  }
034
035  @Override
036  public MecanumDriveKinematics unpack(ProtobufMecanumDriveKinematics msg) {
037    return new MecanumDriveKinematics(
038        Translation2d.proto.unpack(msg.getFrontLeft()),
039        Translation2d.proto.unpack(msg.getFrontRight()),
040        Translation2d.proto.unpack(msg.getRearLeft()),
041        Translation2d.proto.unpack(msg.getRearRight()));
042  }
043
044  @Override
045  public void pack(ProtobufMecanumDriveKinematics msg, MecanumDriveKinematics value) {
046    Translation2d.proto.pack(msg.getMutableFrontLeft(), value.getFrontLeft());
047    Translation2d.proto.pack(msg.getMutableFrontRight(), value.getFrontRight());
048    Translation2d.proto.pack(msg.getMutableRearLeft(), value.getRearLeft());
049    Translation2d.proto.pack(msg.getMutableRearRight(), value.getRearRight());
050  }
051}