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.Quaternion; 008import edu.wpi.first.math.geometry.Rotation3d; 009import edu.wpi.first.util.struct.Struct; 010import java.nio.ByteBuffer; 011 012public class Rotation3dStruct implements Struct<Rotation3d> { 013 @Override 014 public Class<Rotation3d> getTypeClass() { 015 return Rotation3d.class; 016 } 017 018 @Override 019 public String getTypeString() { 020 return "struct:Rotation3d"; 021 } 022 023 @Override 024 public int getSize() { 025 return Quaternion.struct.getSize(); 026 } 027 028 @Override 029 public String getSchema() { 030 return "Quaternion q"; 031 } 032 033 @Override 034 public Struct<?>[] getNested() { 035 return new Struct<?>[] {Quaternion.struct}; 036 } 037 038 @Override 039 public Rotation3d unpack(ByteBuffer bb) { 040 Quaternion q = Quaternion.struct.unpack(bb); 041 return new Rotation3d(q); 042 } 043 044 @Override 045 public void pack(ByteBuffer bb, Rotation3d value) { 046 Quaternion.struct.pack(bb, value.getQuaternion()); 047 } 048}