implement helper functions to determine the struct size and field offsets

This commit is contained in:
2020-03-06 00:17:59 +01:00
parent 622be803cc
commit 1693eb6426

View File

@@ -41,4 +41,22 @@ 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) {
for (int i = 0; i < structDef.fields.length; i++) {
if (structDef.fields[i].name.equals(fieldName)) {
return i * 8;
}
}
return -1;
}
public static int getFieldSizeBytes(StructDefinition structDef) {
return structDef.fields.length * 8;
}
}