Skip to content

Commit

Permalink
Minor cleanup to LogTable
Browse files Browse the repository at this point in the history
Use copyBytes again, and make it static.
  • Loading branch information
kevinclark committed Jan 13, 2024
1 parent 790571b commit 5d5da9d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.util.Objects;
import java.util.Set;

import org.littletonrobotics.junction.LogTable.LogValue;

import edu.wpi.first.units.ImmutableMeasure;
import edu.wpi.first.units.MutableMeasure;
import edu.wpi.first.units.Measure;
Expand Down Expand Up @@ -373,7 +371,7 @@ private <T> byte[] pack(Struct<T> struct, T value) {
return copyBytes(buffer.write(value));
}

private byte[] copyBytes(ByteBuffer bb) {
private static byte[] copyBytes(ByteBuffer bb) {
byte[] array = new byte[bb.position()];
bb.position(0);
bb.get(array);
Expand All @@ -396,10 +394,7 @@ public <T, MessageType extends ProtoMessage<?>> void put(String key, Protobuf<T,
ByteBuffer bb;
try {
bb = buffer.write(value);
byte[] array = new byte[bb.position()];
bb.position(0);
bb.get(array);
put(key, new LogValue(array, proto.getTypeString()));
put(key, new LogValue(copyBytes(bb), proto.getTypeString()));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void protobufIsntWrittenIfKeyAlreadyInUse() {
Assertions.assertEquals(5, table.get("rot").getInteger());
}


@Test
void supportsStructSerialization() {
Rotation2d expected = new Rotation2d(1, 2);
Expand Down

0 comments on commit 5d5da9d

Please sign in to comment.