}
final SerializableField[] fields = sc.getFields();
writeShort(fields.length);
// first write primitive fields, then object fields
for (SerializableField field : fields) {
final Kind kind = field.getKind();
final String name = field.getName();
final Class<?> type;
try {
type = field.getType();
} catch (ClassNotFoundException e) {
// not possible
throw new InvalidClassException(forClass.getName(), "Field " + name + "'s class was not found");
}
if (kind != Kind.OBJECT) {
write(primitives.get(type, -1));
writeUTF(name);
}
}
for (SerializableField field : fields) {
final Kind kind = field.getKind();
final String name = field.getName();
final Class<?> type;
try {
type = field.getType();
} catch (ClassNotFoundException e) {