Flower *flower_loadFromBinaryRepresentation(void **binaryString, CactusDisk *cactusDisk) { Flower *flower = NULL; bool buildFaces; if (binaryRepresentation_peekNextElementType(*binaryString) == CODE_FLOWER) { binaryRepresentation_popNextElementType(binaryString); flower = flower_construct3(binaryRepresentation_getName(binaryString), cactusDisk); //Constructed without an event tree. flower_setBuiltBlocks(flower, binaryRepresentation_getBool(binaryString)); flower_setBuiltTrees(flower, binaryRepresentation_getBool(binaryString)); buildFaces = binaryRepresentation_getBool(binaryString); flower->parentFlowerName = binaryRepresentation_getName(binaryString); eventTree_loadFromBinaryRepresentation(binaryString, flower); while (sequence_loadFromBinaryRepresentation(binaryString, flower) != NULL) ; while (end_loadFromBinaryRepresentation(binaryString, flower) != NULL) ; while (block_loadFromBinaryRepresentation(binaryString, flower) != NULL) ; while (group_loadFromBinaryRepresentation(binaryString, flower) != NULL) ; while (chain_loadFromBinaryRepresentation(binaryString, flower) != NULL) ; flower_setBuildFaces(flower, buildFaces); assert(binaryRepresentation_popNextElementType(binaryString) == CODE_FLOWER); } return flower; }
void testBinaryRepresentation_bool(CuTest* testCase) { cactusSerialisationTestSetup(); void *vA2 = vA; bool i = 0; bool j = 1; binaryRepresentation_writeBool(i, writeFn); binaryRepresentation_writeBool(j, writeFn); CuAssertTrue(testCase, i == binaryRepresentation_getBool(&vA2)); CuAssertTrue(testCase, j == binaryRepresentation_getBool(&vA2)); cactusSerialisationTestTeardown(); }
MetaSequence *metaSequence_loadFromBinaryRepresentation(void **binaryString, CactusDisk *cactusDisk) { MetaSequence *metaSequence; Name name; int64_t start; int64_t length; Name stringName; Name eventName; char *header; metaSequence = NULL; if(binaryRepresentation_peekNextElementType(*binaryString) == CODE_META_SEQUENCE) { binaryRepresentation_popNextElementType(binaryString); name = binaryRepresentation_getName(binaryString); start = binaryRepresentation_getInteger(binaryString); length = binaryRepresentation_getInteger(binaryString); eventName = binaryRepresentation_getName(binaryString); stringName = binaryRepresentation_getName(binaryString); header = binaryRepresentation_getString(binaryString); bool isTrivialSequence = binaryRepresentation_getBool(binaryString); metaSequence = metaSequence_construct2(name, start, length, stringName, header, eventName, isTrivialSequence, cactusDisk); free(header); } return metaSequence; }
static void cactusDisk_loadFromBinaryRepresentation(void **binaryString, CactusDisk *cactusDisk, stKVDatabaseConf *conf) { cactusDisk->sequencesReadFileHandle = NULL; cactusDisk->sequencesWriteFileHandle = NULL; //I think these lines are not needed. cactusDisk->sequencesFileName = NULL; cactusDisk->absSequencesFileName = NULL; assert(binaryRepresentation_peekNextElementType(*binaryString) == CODE_CACTUS_DISK); binaryRepresentation_popNextElementType(binaryString); cactusDisk->storeSequencesInAFile = binaryRepresentation_getBool(binaryString); if (cactusDisk->storeSequencesInAFile) { cactusDisk->sequencesFileName = binaryRepresentation_getString(binaryString); if (stKVDatabaseConf_getDir(conf) == NULL) { stThrowNew(CACTUS_DISK_EXCEPTION_ID, "The database conf does not contain a directory in which the sequence file is to be found!\n"); } cactusDisk->absSequencesFileName = stString_print("%s/%s", stKVDatabaseConf_getDir(conf), cactusDisk->sequencesFileName); } assert(binaryRepresentation_peekNextElementType(*binaryString) == CODE_CACTUS_DISK); binaryRepresentation_popNextElementType(binaryString); }
Event *event_loadFromBinaryRepresentation(void **binaryString, EventTree *eventTree) { Event *event, *parentEvent; Name name; float branchLength; char *header; event = NULL; if (binaryRepresentation_peekNextElementType(*binaryString) == CODE_EVENT) { binaryRepresentation_popNextElementType(binaryString); parentEvent = eventTree_getEvent(eventTree, binaryRepresentation_getName(binaryString)); assert(parentEvent != NULL); name = binaryRepresentation_getName(binaryString); branchLength = binaryRepresentation_getFloat(binaryString); header = binaryRepresentation_getString(binaryString); event = event_construct(name, header, branchLength, parentEvent, eventTree); event_setOutgroupStatus(event, binaryRepresentation_getBool(binaryString)); free(header); } return event; }