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; }
void testBinaryRepresentation_string(CuTest* testCase) { cactusSerialisationTestSetup(); void *vA2 = vA; binaryRepresentation_writeString("HELLO I AM A STRING", writeFn); binaryRepresentation_writeString("GOOD_BYE", writeFn); CuAssertStrEquals(testCase, "HELLO I AM A STRING", binaryRepresentation_getString(&vA2)); CuAssertStrEquals(testCase, "GOOD_BYE", binaryRepresentation_getStringStatic(&vA2)); cactusSerialisationTestTeardown(); }
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; }