std map std string bytearray PrinterPlugin parseIPP fs path filePath s

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
std::map<std::string, bytearray > PrinterPlugin::parseIPP(fs::path filePath) {
std::ifstream fin(filePath, std::ios::binary|std::ios::in);
__scope_guard {
fin.close();
};
std::map<std::string, bytearray> values;
if(!fin.is_open()) {
throw std::runtime_error("Failed to open Metadata file");
}
fin.ignore(8);
char beginAtribute;
fin >> beginAtribute;
while(!fin.eof()) {
char value_tag;
fin >> value_tag;
int valueNum = value_tag;
if(valueNum >= 0 && valueNum <= 15) {
if(value_tag == '\x03') break;
fin.ignore(1); // Новый тэг атрибут группы
}
char length[2];
fin.readsome(length, 2);
int nameLength = length[1] | length[0] << 8;
char attrName[nameLength+1];
fin.readsome(attrName, nameLength);
attrName[nameLength] = '\0';
fin.readsome(length, 2);
int valueLength = length[1] | length[0] << 8;
bytearray value(valueLength);
fin.readsome(reinterpret_cast<char *>(value.data()), valueLength);
values[attrName] = value;
}
return values;
}