implement method that returns the index of a field by name
This commit is contained in:
@@ -42,20 +42,24 @@ public class Helper {
|
||||
throw new RuntimeException("Struct " + structDef.name + " does not contain field " + path[pathIndex]);
|
||||
}
|
||||
|
||||
public static int getFieldOffset(StructDefinition structDef, int fieldIndex) {
|
||||
return fieldIndex * 8;
|
||||
}
|
||||
|
||||
public static int getFieldOffset(StructDefinition structDef, String fieldName) {
|
||||
public static int getFieldIndex(StructDefinition structDef, String fieldName) {
|
||||
for (int i = 0; i < structDef.fields.length; i++) {
|
||||
if (structDef.fields[i].name.equals(fieldName)) {
|
||||
return i * 8;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
return structDef.fields.length * 8;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user