mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
[wpiutil] Record/Enum struct generation fix (#7538)
ProceduralStructGenerator's genRecord and genEnum were package-private, and only extractClassStruct was made public. However, this package private visibility rendered them unable to be used by the rest of wpilib(and advanced users). Here, ProceduralStructGenerator is split into 2 classes: StructGenerator(which generates structs) and StructFetcher(the new namespace for extractClassStruct). In addition, genRecord and genEnum have been made public methods.
This commit is contained in:
@@ -4,15 +4,15 @@
|
||||
|
||||
package edu.wpi.first.util.struct;
|
||||
|
||||
import static edu.wpi.first.util.struct.ProceduralStructGenerator.genEnum;
|
||||
import static edu.wpi.first.util.struct.ProceduralStructGenerator.genRecord;
|
||||
import static edu.wpi.first.util.struct.StructGenerator.genEnum;
|
||||
import static edu.wpi.first.util.struct.StructGenerator.genRecord;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ProceduralStructGeneratorTest {
|
||||
class StructGeneratorTest {
|
||||
public record CustomRecord(int int32, boolean bool, double float64, char character, short int16)
|
||||
implements StructSerializable {
|
||||
public static CustomRecord create() {
|
||||
@@ -95,8 +95,7 @@ class ProceduralStructGeneratorTest {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <S extends StructSerializable> void testStructRoundTrip(S value) {
|
||||
Struct<S> struct =
|
||||
ProceduralStructGenerator.extractClassStruct((Class<S>) value.getClass()).get();
|
||||
Struct<S> struct = StructFetcher.fetchStruct((Class<S>) value.getClass()).get();
|
||||
ByteBuffer buffer = ByteBuffer.allocate(struct.getSize());
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
struct.pack(buffer, value);
|
||||
@@ -108,8 +107,7 @@ class ProceduralStructGeneratorTest {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <S extends StructSerializable> void testStructDoublePack(S value) {
|
||||
Struct<S> struct =
|
||||
ProceduralStructGenerator.extractClassStruct((Class<S>) value.getClass()).get();
|
||||
Struct<S> struct = StructFetcher.fetchStruct((Class<S>) value.getClass()).get();
|
||||
ByteBuffer buffer = ByteBuffer.allocate(struct.getSize());
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
struct.pack(buffer, value);
|
||||
@@ -123,8 +121,7 @@ class ProceduralStructGeneratorTest {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <S extends StructSerializable> void testStructDoubleUnpack(S value) {
|
||||
Struct<S> struct =
|
||||
ProceduralStructGenerator.extractClassStruct((Class<S>) value.getClass()).get();
|
||||
Struct<S> struct = StructFetcher.fetchStruct((Class<S>) value.getClass()).get();
|
||||
ByteBuffer buffer = ByteBuffer.allocate(struct.getSize());
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
struct.pack(buffer, value);
|
||||
Reference in New Issue
Block a user