/** Computes the size in bytes that this state will occupy, when serialized as a Slice */ private static int serializedSizeOf(Class<?> stateClass) { List<StateField> fields = enumerateFields(stateClass); int size = 0; for (StateField field : fields) { size += field.sizeOfType(); } return size; }
/** Computes the byte offset to store this field at, when serializing it to a Slice */ private static int offsetOfField(StateField targetField, List<StateField> fields) { int offset = 0; for (StateField field : fields) { if (targetField.getName().equals(field.getName())) { break; } offset += field.sizeOfType(); } return offset; }