struct foo { int a; int b; const char *c; };
void serialize_foo(foo &obj, ostream &out) { out.serialize_int(obj.a); out.serialize_int(obj.b); out.serialize_string(obj.c); }
void emit_serialize_method(class_definition &clazz) { emit("void serialize_foo(" + clazz.name + "&obj, ostream &out) {"); for (auto &field : clazz.fields) { emit(" out.serialize_" + field.type + "(obj." + field.name + ");"); } emit("}"); }