/** * Convert struct to byte array. * Userdata is currently only PCDIMSTATS, hopefully updated across * a number of iterations and saved. */ SERIALIZED_PATCH * pc_patch_serialize(const PCPATCH *patch_in, void *userdata) { PCPATCH *patch = (PCPATCH*)patch_in; SERIALIZED_PATCH *serpatch = NULL; /* * Ensure the patch has stats calculated before going on */ if ( ! patch->stats ) { pcerror("%s: patch is missing stats", __func__); return NULL; } /* * Convert the patch to the final target compression, * which is the one in the schema. */ if ( patch->type != patch->schema->compression ) { patch = pc_patch_compress(patch_in, userdata); } switch( patch->type ) { case PC_NONE: { serpatch = pc_patch_uncompressed_serialize(patch); break; } case PC_DIMENSIONAL: { serpatch = pc_patch_dimensional_serialize(patch); break; } case PC_GHT: { serpatch = pc_patch_ght_serialize(patch); break; } default: { pcerror("%s: unsupported compression type %d", __func__, patch->type); } } if ( patch != patch_in ) pc_patch_free(patch); return serpatch; }
/** * Convert struct to byte array. * Userdata is currently only PCDIMSTATS, hopefully updated across * a number of iterations and saved. */ SERIALIZED_PATCH * pc_patch_serialize(const PCPATCH *patch_in, void *userdata) { PCPATCH *patch = (PCPATCH*)patch_in; SERIALIZED_PATCH *serpatch; /* * Convert the patch to the final target compression, * which is the one in the schema. */ if ( patch->type != patch->schema->compression ) { patch = pc_patch_compress(patch_in, userdata); } switch( patch->type ) { case PC_NONE: serpatch = pc_patch_uncompressed_serialize(patch); break; case PC_DIMENSIONAL: { serpatch = pc_patch_dimensional_serialize(patch); break; } case PC_GHT: { pcerror("pc_patch_serialize: GHT compression currently unsupported"); break; } default: { pcerror("pc_patch_serialize: unsupported compression type %d", patch->type); } } if ( patch != patch_in ) pc_patch_free(patch); return serpatch; }