| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "dico_replace_var.h" | ||
| 8 | #include "phoenix_varint.h" | ||
| 9 | #include "phoenix_field.h" | ||
| 10 | |||
| 11 | ///Reads a Field header | ||
| 12 | /** @param[out] fieldId : id of the current field | ||
| 13 | * @param[out] fieldType : type of the current field | ||
| 14 | * @param[out] iter : iterator ofer the message to be read | ||
| 15 | */ | ||
| 16 | 59 | void phoenix_field(size_t & fieldId, size_t & fieldType, char*& iter){ | |
| 17 | 59 | char value = *iter; | |
| 18 | 59 | fieldType = value & 7; //Get 3 first bits | |
| 19 | 59 | fieldId = value >> 3; //Shifted of 3 bits on the left | |
| 20 | 59 | iter += 1lu; | |
| 21 | 59 | } | |
| 22 | |||
| 23 | ///Skip the current field | ||
| 24 | /** @param[out] iter : iterator of the current message to be read | ||
| 25 | * @param fieldType : type of the field to be skipped | ||
| 26 | */ | ||
| 27 | 12 | void phoenix_fieldSkip(char*& iter, size_t fieldType){ | |
| 28 |
5/5✓ Branch 0 (2→3) taken 4 times.
✓ Branch 1 (2→5) taken 1 times.
✓ Branch 2 (2→6) taken 5 times.
✓ Branch 3 (2→8) taken 1 times.
✓ Branch 4 (2→9) taken 1 times.
|
12 | switch(fieldType){ |
| 29 | 4 | case 0lu: //This is an enum | |
| 30 | 4 | phoenix_skipVarInt(iter); | |
| 31 | 4 | break; | |
| 32 | 1 | case 1lu: //This is a uint64_t | |
| 33 | 1 | iter += sizeof(uint64_t); | |
| 34 | 1 | break; | |
| 35 | 5 | case 2lu: //This is a binary array, which starts by a varint | |
| 36 | 5 | iter += phoenix_readVarInt(iter); | |
| 37 | 5 | break; | |
| 38 | 1 | case 5lu: //This is a uint64_t | |
| 39 | 1 | iter += sizeof(uint32_t); | |
| 40 | 1 | break; | |
| 41 | 1 | default: | |
| 42 | 1 | break; | |
| 43 | } | ||
| 44 | 12 | } | |
| 45 | |||
| 46 | ///Print the current ByteArray | ||
| 47 | /** @param[out] iter : iterator of the current message to be read | ||
| 48 | * @param message : message to be used | ||
| 49 | */ | ||
| 50 | 2 | void phoenix_fieldPrintArray(char*& iter, const char * message){ | |
| 51 | 2 | size_t nbByte = phoenix_readVarInt(iter); | |
| 52 | 2 | size_t dataOffset = iter - (char*)message; | |
| 53 | 2 | std::cout << "ByteArray/SubMessage(data_offset = " << dataOffset << ", size = " << nbByte << ")" << std::endl; | |
| 54 | 2 | iter += nbByte; | |
| 55 | 2 | } | |
| 56 | |||
| 57 | ///Print the current field | ||
| 58 | /** @param[out] iter : iterator of the current message to be read | ||
| 59 | * @param fieldType : type of the field to be skipped | ||
| 60 | * @param message : message to be used | ||
| 61 | */ | ||
| 62 | 4 | void phoenix_fieldPrint(char*& iter, size_t fieldType, const char * message){ | |
| 63 |
3/5✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→8) not taken.
✓ Branch 2 (2→13) taken 2 times.
✓ Branch 3 (2→15) taken 1 times.
✗ Branch 4 (2→20) not taken.
|
4 | switch(fieldType){ |
| 64 | 1 | case 0lu: //This is an enum | |
| 65 | 1 | std::cout << "Enum = " << phoenix_readVarInt(iter) << std::endl; | |
| 66 | 1 | break; | |
| 67 | ✗ | case 1lu: //This is a uint64_t | |
| 68 | ✗ | std::cout << "uint64_t = " << phoenix_readValue<uint64_t>(iter) << std::endl; | |
| 69 | ✗ | break; | |
| 70 | 2 | case 2lu: //This is a binary array, which starts by a varint | |
| 71 | 2 | phoenix_fieldPrintArray(iter, message); | |
| 72 | 2 | break; | |
| 73 | 1 | case 5lu: //This is a uint64_t | |
| 74 | 1 | std::cout << "uint32_t = " << phoenix_readValue<uint32_t>(iter) << std::endl; | |
| 75 | 1 | break; | |
| 76 | ✗ | default: | |
| 77 | ✗ | std::cout << "Unknown Type" << std::endl; | |
| 78 | ✗ | break; | |
| 79 | } | ||
| 80 | 4 | } | |
| 81 | |||
| 82 | ///Create a FieldConfig | ||
| 83 | /** @param type : type of the field | ||
| 84 | * @param id : id of the field | ||
| 85 | * @param name : name of the field | ||
| 86 | * @param isArray : true if the field is an array | ||
| 87 | * @return corresponding FieldConfig | ||
| 88 | */ | ||
| 89 | 23 | FieldConfig phoenix_createField(FieldType::FieldType type, size_t id, const PString & name, bool isArray){ | |
| 90 | 23 | FieldConfig field; | |
| 91 |
1/1✓ Branch 0 (3→4) taken 23 times.
|
23 | field.setType(type); |
| 92 |
1/1✓ Branch 0 (4→5) taken 23 times.
|
23 | field.setId(id); |
| 93 |
1/1✓ Branch 0 (5→6) taken 23 times.
|
23 | field.setName(name); |
| 94 |
1/1✓ Branch 0 (6→7) taken 23 times.
|
23 | field.setIsArray(isArray); |
| 95 | 23 | return field; | |
| 96 | ✗ | } | |
| 97 | |||
| 98 | ///Parse a yml file and search for a field_config key | ||
| 99 | /** @param[out] field : fieldConfig to be initialised | ||
| 100 | * @param fileName : name of the yml file to be loaded | ||
| 101 | * @param fieldConfigKey : name of the key to be searched in the yml file to initialise the FieldConfig | ||
| 102 | * @return true on success, false otherwise | ||
| 103 | */ | ||
| 104 | 2 | bool phoenix_parseFieldConfig(FieldConfig & field, const PPath & fileName, const PString & fieldConfigKey){ | |
| 105 |
1/1✓ Branch 0 (2→3) taken 2 times.
|
2 | DicoValue dico; |
| 106 |
2/3✓ Branch 0 (3→4) taken 2 times.
✗ Branch 2 (4→5) not taken.
✓ Branch 3 (4→10) taken 2 times.
|
2 | if(!parser_yml(dico, fileName)){ |
| 107 | ✗ | std::cerr << "phoenix_parseFieldConfig : cannot open yml file '"<<fileName<<"'" << std::endl; | |
| 108 | ✗ | return false; | |
| 109 | } | ||
| 110 |
2/2✓ Branch 0 (10→11) taken 2 times.
✓ Branch 2 (11→12) taken 2 times.
|
2 | dico_replace_var(dico); |
| 111 |
3/3✓ Branch 0 (13→14) taken 2 times.
✓ Branch 2 (14→15) taken 1 times.
✓ Branch 3 (14→20) taken 1 times.
|
2 | if(!phoenix_parseFieldConfig(field, dico, fieldConfigKey)){ |
| 112 |
4/4✓ Branch 0 (15→16) taken 1 times.
✓ Branch 2 (16→17) taken 1 times.
✓ Branch 4 (17→18) taken 1 times.
✓ Branch 6 (18→19) taken 1 times.
|
1 | std::cerr << "phoenix_parseFieldConfig : cannot parse yml file '"<<fileName<<"'" << std::endl; |
| 113 | 1 | return false; | |
| 114 | }else{ | ||
| 115 | 1 | return true; | |
| 116 | } | ||
| 117 | 2 | } | |
| 118 | |||
| 119 | ///Load a fieldConfig with a DicoValue (parsed yml file) | ||
| 120 | /** @param[out] field : fieldConfig to be initialised | ||
| 121 | * @param dico : DicoValue which contains the FieldConfig definition | ||
| 122 | * @param fieldConfigKey : name of the key to be searched in the yml file to initialise the FieldConfig | ||
| 123 | * @return true on success, false otherwise | ||
| 124 | */ | ||
| 125 | 5 | bool phoenix_parseFieldConfig(FieldConfig & field, const DicoValue & dico, const PString & fieldConfigKey){ | |
| 126 | 5 | const DicoValue * ymlField = dico.getMap(fieldConfigKey); | |
| 127 |
1/2✓ Branch 0 (3→4) taken 5 times.
✗ Branch 1 (3→6) not taken.
|
5 | if(ymlField != NULL){ |
| 128 | 5 | return phoenix_parseFieldConfig(field, *ymlField); | |
| 129 | }else{ | ||
| 130 | ✗ | std::cerr << "phoenix_parseFieldConfig : FieldConfig definition '"<<fieldConfigKey<<"' does not exist in yml file" << std::endl; | |
| 131 | ✗ | return false; | |
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | ///Load a fieldConfig with a DicoValue (parsed yml file) | ||
| 136 | /** @param[out] field : fieldConfig to be initialised | ||
| 137 | * @param dico : DicoValue which contains the FieldConfig definition | ||
| 138 | * @return true on success, false otherwise | ||
| 139 | */ | ||
| 140 | 5 | bool phoenix_parseFieldConfig(FieldConfig & field, const DicoValue & dico){ | |
| 141 | 5 | const MapDicoValue & mapChildren = dico.getMapChild(); | |
| 142 |
2/2✓ Branch 0 (82→4) taken 13 times.
✓ Branch 1 (82→83) taken 3 times.
|
16 | for(MapDicoValue::const_iterator it(mapChildren.begin()); it != mapChildren.end(); ++it){ |
| 143 |
1/1✓ Branch 0 (5→6) taken 13 times.
|
13 | PString name(it->first); |
| 144 |
2/2✓ Branch 0 (6→7) taken 13 times.
✓ Branch 2 (8→9) taken 13 times.
|
13 | size_t id(phoenix_load_value_from_config<size_t>(it->second, "id", 0lu)); |
| 145 |
3/3✓ Branch 0 (10→11) taken 13 times.
✓ Branch 2 (11→12) taken 13 times.
✓ Branch 4 (13→14) taken 13 times.
|
13 | PString typeStr(phoenix_get_string(it->second, "type", "uint64")); |
| 146 |
2/2✓ Branch 0 (16→17) taken 13 times.
✓ Branch 2 (18→19) taken 13 times.
|
13 | bool isArray(phoenix_load_value_from_config<bool>(it->second, "is_array", false)); |
| 147 |
1/1✓ Branch 0 (20→21) taken 13 times.
|
13 | FieldType::FieldType type(phoenix_fieldTypeFromStr(typeStr)); |
| 148 |
2/2✓ Branch 0 (21→22) taken 12 times.
✓ Branch 1 (21→43) taken 1 times.
|
13 | if(type != FieldType::NONE){ |
| 149 |
1/1✓ Branch 0 (22→23) taken 12 times.
|
12 | FieldConfig subField = phoenix_createField(type, id, name, isArray); |
| 150 |
2/2✓ Branch 0 (23→24) taken 3 times.
✓ Branch 1 (23→34) taken 9 times.
|
12 | if(type == FieldType::SUBMESSAGE){ //We check only the submessage definition with the type is FieldType::SUBMESSAGE |
| 151 |
4/4✓ Branch 0 (24→25) taken 3 times.
✓ Branch 2 (26→27) taken 3 times.
✓ Branch 4 (28→29) taken 1 times.
✓ Branch 5 (28→34) taken 2 times.
|
3 | if(!phoenix_parseFieldConfig(subField, it->second, "sub_message")){ |
| 152 |
4/4✓ Branch 0 (29→30) taken 1 times.
✓ Branch 2 (30→31) taken 1 times.
✓ Branch 4 (31→32) taken 1 times.
✓ Branch 6 (32→33) taken 1 times.
|
1 | std::cerr << "phoenix_parseFieldConfig : cannot parse 'sub_message' of Field '"<<name<<"'" << std::endl; |
| 153 | 1 | return false; | |
| 154 | } | ||
| 155 | } | ||
| 156 |
3/3✓ Branch 0 (34→35) taken 11 times.
✓ Branch 2 (35→36) taken 11 times.
✓ Branch 4 (36→37) taken 11 times.
|
11 | field.getVecChildren()[name] = subField; |
| 157 |
2/2✓ Branch 0 (39→40) taken 11 times.
✓ Branch 1 (39→42) taken 1 times.
|
12 | }else{ |
| 158 |
6/6✓ Branch 0 (43→44) taken 1 times.
✓ Branch 2 (44→45) taken 1 times.
✓ Branch 4 (45→46) taken 1 times.
✓ Branch 6 (46→47) taken 1 times.
✓ Branch 8 (47→48) taken 1 times.
✓ Branch 10 (48→49) taken 1 times.
|
1 | std::cerr << "phoenix_parseFieldConfig : type '"<<typeStr<<"' does not exist for Field '"<<name<<"'. Please use one of :" << std::endl; |
| 159 |
2/2✓ Branch 0 (49→50) taken 1 times.
✓ Branch 2 (50→51) taken 1 times.
|
1 | std::cerr << "\t- enum" << std::endl; |
| 160 |
2/2✓ Branch 0 (51→52) taken 1 times.
✓ Branch 2 (52→53) taken 1 times.
|
1 | std::cerr << "\t- submessage" << std::endl; |
| 161 |
2/2✓ Branch 0 (53→54) taken 1 times.
✓ Branch 2 (54→55) taken 1 times.
|
1 | std::cerr << "\t- uint64" << std::endl; |
| 162 |
2/2✓ Branch 0 (55→56) taken 1 times.
✓ Branch 2 (56→57) taken 1 times.
|
1 | std::cerr << "\t- uint32" << std::endl; |
| 163 |
2/2✓ Branch 0 (57→58) taken 1 times.
✓ Branch 2 (58→59) taken 1 times.
|
1 | std::cerr << "\t- uint16" << std::endl; |
| 164 |
2/2✓ Branch 0 (59→60) taken 1 times.
✓ Branch 2 (60→61) taken 1 times.
|
1 | std::cerr << "\t- uint8" << std::endl; |
| 165 |
2/2✓ Branch 0 (61→62) taken 1 times.
✓ Branch 2 (62→63) taken 1 times.
|
1 | std::cerr << "\t- int64" << std::endl; |
| 166 |
2/2✓ Branch 0 (63→64) taken 1 times.
✓ Branch 2 (64→65) taken 1 times.
|
1 | std::cerr << "\t- int32" << std::endl; |
| 167 |
2/2✓ Branch 0 (65→66) taken 1 times.
✓ Branch 2 (66→67) taken 1 times.
|
1 | std::cerr << "\t- int16" << std::endl; |
| 168 |
2/2✓ Branch 0 (67→68) taken 1 times.
✓ Branch 2 (68→69) taken 1 times.
|
1 | std::cerr << "\t- int8" << std::endl; |
| 169 | 1 | return false; | |
| 170 | } | ||
| 171 | 15 | } | |
| 172 | 3 | return true; | |
| 173 | } | ||
| 174 | |||
| 175 | ///Print the Fields in a message | ||
| 176 | /** @param message : message to be used | ||
| 177 | * @param nbByte : number of bytes of the message | ||
| 178 | * @param offset : offset to start reading the message | ||
| 179 | */ | ||
| 180 | 1 | void phoenix_printFieldMessage(const char * message, size_t nbByte, size_t offset){ | |
| 181 | 1 | char* iter = (char*)message + offset; | |
| 182 | 1 | size_t messageSize = nbByte - offset; | |
| 183 |
2/2✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
|
1 | std::cout << "Field{" << std::endl; |
| 184 |
2/2✓ Branch 0 (13→5) taken 4 times.
✓ Branch 1 (13→14) taken 1 times.
|
5 | while(iter < message + messageSize){ |
| 185 | 4 | size_t fieldId(0lu), fieldType(0lu); | |
| 186 |
1/1✓ Branch 0 (5→6) taken 4 times.
|
4 | phoenix_field(fieldId, fieldType, iter); |
| 187 | 4 | size_t fieldOffset = iter - (char*)message; | |
| 188 |
5/5✓ Branch 0 (6→7) taken 4 times.
✓ Branch 2 (7→8) taken 4 times.
✓ Branch 4 (8→9) taken 4 times.
✓ Branch 6 (9→10) taken 4 times.
✓ Branch 8 (10→11) taken 4 times.
|
4 | std::cout << "\t- Field " << fieldId << " : field_offset = " << fieldOffset << ", "; |
| 189 |
1/1✓ Branch 0 (11→12) taken 4 times.
|
4 | phoenix_fieldPrint(iter, fieldType, message); |
| 190 | } | ||
| 191 |
2/2✓ Branch 0 (14→15) taken 1 times.
✓ Branch 2 (15→16) taken 1 times.
|
1 | std::cout << "}" << std::endl; |
| 192 | 1 | } | |
| 193 | |||
| 194 | ///Print the Fields in a message | ||
| 195 | /** @param message : message to be used | ||
| 196 | * @param nbByte : number of bytes of the message | ||
| 197 | */ | ||
| 198 | 1 | void phoenix_printFieldMessage(const char * message, size_t nbByte){ | |
| 199 | 1 | phoenix_printFieldMessage(message, nbByte, 0lu); | |
| 200 | 1 | } | |
| 201 | |||
| 202 |