| 1 | #include <stdlib.h> |
| 2 | #include "Util/types.h" |
| 3 | #include "Util/utils.h" |
| 4 | |
| 5 | // deserialize a Work_t object from a bytes string |
| 6 | Work_t* unpack_work(Byte* packedWork, uint32_t nbSeriesInChunk) |
| 7 | { |
| 8 | Work_t* work = (Work_t*) malloc(sizeof(Work_t)); |
| 9 | |
| 10 | uint32_t index = 0; |
| 11 | |
| 12 | size_t inputFileNameSize = 0; |
| 13 | while (packedWork[inputFileNameSize++] != 0) { } |
| 14 | work->inputFileName = (char*) malloc(inputFileNameSize); |
| 15 | while (index < inputFileNameSize) |
| 16 | { |
| 17 | work->inputFileName[index] = packedWork[index]; |
| 18 | index++; |
| 19 | } |
| 20 | |
| 21 | index = NCHAR_FNAME; |
| 22 | |
| 23 | uint32_t nbSeries = work->nbSeries = bInt_to_uint(packedWork + index, 4); |
| 24 | index += 4; |
| 25 | |
| 26 | work->ranks = (uint32_t*) malloc(nbSeries * sizeof(uint32_t)); |
| 27 | for (uint32_t i = 0; i < nbSeries; i++) |
| 28 | { |
| 29 | work->ranks[i] = bInt_to_uint(packedWork + index, 4); |
| 30 | index += 4; |
| 31 | } |
| 32 | // shift over the zeros |
| 33 | index += 4 * (nbSeriesInChunk - nbSeries); |
| 34 | |
| 35 | work->nbClusters = bInt_to_uint(packedWork + index, 4); |
| 36 | index += 4; |
| 37 | work->clustOnMedoids = bInt_to_uint(packedWork + index, 4); |
| 38 | index += 4; |
| 39 | work->p_for_dissims = bInt_to_uint(packedWork + index, 4); |
| 40 | |
| 41 | return work; |
| 42 | } |
| 43 | |
| 44 | // deserialize a Result_t object from a bytes string |
| 45 | Result_t* unpack_result(Byte* packedResult) |
| 46 | { |
| 47 | Result_t* result = (Result_t*) malloc(sizeof(Result_t)); |
| 48 | uint32_t index = 0; |
| 49 | |
| 50 | uint32_t nbClusters = result->nbClusters = bInt_to_uint(packedResult, 4); |
| 51 | index += 4; |
| 52 | |
| 53 | result->medoids_ID = (uint32_t*) malloc(nbClusters * sizeof(uint32_t)); |
| 54 | for (uint32_t i = 0; i < nbClusters; i++) |
| 55 | { |
| 56 | result->medoids_ID[i] = bInt_to_uint(packedResult + index, 4); |
| 57 | index += 4; |
| 58 | } |
| 59 | |
| 60 | result->medoids_ranks = (uint32_t*) malloc(nbClusters * sizeof(uint32_t)); |
| 61 | for (uint32_t i = 0; i < nbClusters; i++) |
| 62 | { |
| 63 | result->medoids_ranks[i] = bInt_to_uint(packedResult + index, 4); |
| 64 | index += 4; |
| 65 | } |
| 66 | |
| 67 | return result; |
| 68 | } |