implement method that returns the index of a field by name

This commit is contained in:
2020-03-07 00:14:06 +01:00
parent e3d8f3cfa7
commit 32cb06cd51

View File

@@ -42,20 +42,24 @@ public class Helper {
throw new RuntimeException("Struct " + structDef.name + " does not contain field " + path[pathIndex]); throw new RuntimeException("Struct " + structDef.name + " does not contain field " + path[pathIndex]);
} }
public static int getFieldOffset(StructDefinition structDef, int fieldIndex) { public static int getFieldIndex(StructDefinition structDef, String fieldName) {
return fieldIndex * 8;
}
public static int getFieldOffset(StructDefinition structDef, String fieldName) {
for (int i = 0; i < structDef.fields.length; i++) { for (int i = 0; i < structDef.fields.length; i++) {
if (structDef.fields[i].name.equals(fieldName)) { if (structDef.fields[i].name.equals(fieldName)) {
return i * 8; return i;
} }
} }
return -1; return -1;
} }
public static int getFieldOffset(StructDefinition structDef, int fieldIndex) {
return fieldIndex * 8;
}
public static int getFieldOffset(StructDefinition structDef, String fieldName) {
return getFieldIndex(structDef, fieldName) * 8;
}
public static int getFieldSizeBytes(StructDefinition structDef) { public static int getFieldSizeBytes(StructDefinition structDef) {
return structDef.fields.length * 8; return structDef.fields.length * 8;
} }