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.struct;
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.util.struct.Struct;
011import java.nio.ByteBuffer;
012
013public class Transform3dStruct implements Struct<Transform3d> {
014  @Override
015  public Class<Transform3d> getTypeClass() {
016    return Transform3d.class;
017  }
018
019  @Override
020  public String getTypeString() {
021    return "struct:Transform3d";
022  }
023
024  @Override
025  public int getSize() {
026    return Translation3d.struct.getSize() + Rotation3d.struct.getSize();
027  }
028
029  @Override
030  public String getSchema() {
031    return "Translation3d translation;Rotation3d rotation";
032  }
033
034  @Override
035  public Struct<?>[] getNested() {
036    return new Struct<?>[] {Translation3d.struct, Rotation3d.struct};
037  }
038
039  @Override
040  public Transform3d unpack(ByteBuffer bb) {
041    Translation3d translation = Translation3d.struct.unpack(bb);
042    Rotation3d rotation = Rotation3d.struct.unpack(bb);
043    return new Transform3d(translation, rotation);
044  }
045
046  @Override
047  public void pack(ByteBuffer bb, Transform3d value) {
048    Translation3d.struct.pack(bb, value.getTranslation());
049    Rotation3d.struct.pack(bb, value.getRotation());
050  }
051}