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 org.wpilib.math.kinematics.struct;
006
007import java.nio.ByteBuffer;
008import org.wpilib.math.geometry.Rotation2d;
009import org.wpilib.math.kinematics.SwerveModuleAcceleration;
010import org.wpilib.util.struct.Struct;
011
012public class SwerveModuleAccelerationStruct implements Struct<SwerveModuleAcceleration> {
013  @Override
014  public Class<SwerveModuleAcceleration> getTypeClass() {
015    return SwerveModuleAcceleration.class;
016  }
017
018  @Override
019  public String getTypeName() {
020    return "SwerveModuleAccelerations";
021  }
022
023  @Override
024  public int getSize() {
025    return kSizeDouble + Rotation2d.struct.getSize();
026  }
027
028  @Override
029  public String getSchema() {
030    return "double acceleration;Rotation2d angle";
031  }
032
033  @Override
034  public Struct<?>[] getNested() {
035    return new Struct<?>[] {Rotation2d.struct};
036  }
037
038  @Override
039  public SwerveModuleAcceleration unpack(ByteBuffer bb) {
040    double acceleration = bb.getDouble();
041    Rotation2d angle = Rotation2d.struct.unpack(bb);
042    return new SwerveModuleAcceleration(acceleration, angle);
043  }
044
045  @Override
046  public void pack(ByteBuffer bb, SwerveModuleAcceleration value) {
047    bb.putDouble(value.acceleration);
048    Rotation2d.struct.pack(bb, value.angle);
049  }
050}