Skip to content

Commit c96ebf3

Browse files
committed
Use rawDataHex more consistently.
1 parent 42f03c8 commit c96ebf3

8 files changed

Lines changed: 36 additions & 33 deletions

File tree

quicklook/TIVarsQuickLookSupport.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void sanitize_json_for_preview(json& value, const std::string& key = std::string
232232
const size_t omittedChars = str.size() - 256;
233233
value = str.substr(0, 256) + "... [preview truncated, " + std::to_string(omittedChars) + " more characters]";
234234
}
235-
else if ((key == "rawDataHex" || key == "calcDataHex" || key == "dataHex") && str.size() > 256)
235+
else if (key == "rawDataHex" && str.size() > 256)
236236
{
237237
value = str.substr(0, 256) + "... [preview truncated, " + std::to_string(str.size() / 2) + " bytes total]";
238238
}

schemas/cabrijr-appvar.schema.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"type": "integer",
5858
"readOnly": true
5959
},
60-
"dataHex": {
60+
"rawDataHex": {
6161
"$ref": "#/definitions/hexString"
6262
},
6363
"unreadHex": {
@@ -109,9 +109,6 @@
109109
"items": {
110110
"type": "string"
111111
}
112-
},
113-
"rawDataHex": {
114-
"$ref": "#/definitions/hexString"
115112
}
116113
},
117114
"additionalProperties": false

schemas/flash.schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
"type": "string",
4242
"pattern": "^[0-9A-Fa-f]{2}$"
4343
},
44-
"dataHex": {
44+
"rawDataHex": {
4545
"$ref": "#/definitions/hexStringOrEllipsis"
4646
}
4747
},
48-
"required": ["address", "blockType", "dataHex"],
48+
"required": ["address", "blockType", "rawDataHex"],
4949
"additionalProperties": false
5050
},
5151
"flashField": {
@@ -232,7 +232,7 @@
232232
"hasChecksum": {
233233
"type": "boolean"
234234
},
235-
"calcDataHex": {
235+
"rawDataHex": {
236236
"$ref": "#/definitions/hexStringOrEllipsis"
237237
},
238238
"license": {

schemas/python-appvar.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"minimum": 0,
1616
"maximum": 255
1717
},
18-
"dataHex": {
18+
"rawDataHex": {
1919
"$ref": "#/definitions/hexString"
2020
},
2121
"name": {
@@ -32,7 +32,7 @@
3232
},
3333
"required": ["type"],
3434
"anyOf": [
35-
{ "required": ["dataHex"] },
35+
{ "required": ["rawDataHex"] },
3636
{ "required": ["name"] },
3737
{ "required": ["text"] }
3838
],

src/TIFlashFile.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ namespace tivars
794794

795795
if (header.binaryFlag == rawBinaryDataFlag)
796796
{
797-
j["calcDataHex"] = (header.calcData.size() <= 256) ? toHex(header.calcData) : "...";
797+
j["rawDataHex"] = (header.calcData.size() <= 256) ? toHex(header.calcData) : "...";
798798
try
799799
{
800800
j["fields"] = parse_flash_fields(header.calcData, 0, header.calcData.size());
@@ -821,7 +821,7 @@ namespace tivars
821821
j["blocks"].push_back({
822822
{"address", toHex({static_cast<uint8_t>((address >> 8) & 0xFF), static_cast<uint8_t>(address & 0xFF)})},
823823
{"blockType", dechex(blockType)},
824-
{"dataHex", toHex(data)},
824+
{"rawDataHex", toHex(data)},
825825
});
826826
}
827827
try
@@ -928,14 +928,14 @@ namespace tivars
928928
blocks.emplace_back(
929929
static_cast<uint16_t>((addressBytes[0] << 8) | addressBytes[1]),
930930
hexdec(item.at("blockType").get<std::string>()),
931-
parseHex(item.at("dataHex").get<std::string>())
931+
parseHex(item.at("rawDataHex").get<std::string>())
932932
);
933933
}
934934
calcData = makeIntelData(blocks);
935935
}
936-
else if (j.contains("calcDataHex"))
936+
else if (j.contains("rawDataHex"))
937937
{
938-
calcData = parseHex(j.at("calcDataHex").get<std::string>());
938+
calcData = parseHex(j.at("rawDataHex").get<std::string>());
939939
}
940940
else if (type.getName() == "FlashLicense" && j.contains("license"))
941941
{

src/TypeHandlers/STH_PythonAppVar.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ namespace tivars::TypeHandlers
311311
{
312312
json out = {
313313
{"type", record.type},
314-
{"dataHex", to_hex_string(record.data)},
314+
{"rawDataHex", to_hex_string(record.data)},
315315
{"length", record.data.size() + 1},
316316
};
317317
if (record.type == metadataRecordTypeFilename)
@@ -347,12 +347,12 @@ namespace tivars::TypeHandlers
347347
continue;
348348
}
349349

350-
if (recordJson.contains("dataHex"))
350+
if (recordJson.contains("rawDataHex"))
351351
{
352-
const std::string hex = recordJson.at("dataHex").get<std::string>();
352+
const std::string hex = recordJson.at("rawDataHex").get<std::string>();
353353
if (hex.size() % 2 != 0)
354354
{
355-
throw std::invalid_argument("metadataRecords.dataHex must contain an even number of hex digits");
355+
throw std::invalid_argument("metadataRecords.rawDataHex must contain an even number of hex digits");
356356
}
357357
record.data.reserve(hex.size() / 2);
358358
for (size_t i = 0; i < hex.size(); i += 2)
@@ -372,7 +372,7 @@ namespace tivars::TypeHandlers
372372
}
373373
else
374374
{
375-
throw std::invalid_argument("metadataRecords entries need dataHex, name, or text");
375+
throw std::invalid_argument("metadataRecords entries need rawDataHex, name, or text");
376376
}
377377

378378
records.push_back(record);

src/TypeHandlers/TH_StructuredAppVar.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ namespace tivars::TypeHandlers
499499

500500
data_t payload_from_json_or_raw(const json& j, StructuredAppVarSubtype subtype)
501501
{
502-
if (j.contains("rawDataHex"))
502+
if (j.contains("rawDataHex") && !(subtype == APPVAR_SUBTYPE_CABRIJR && j.contains("variant")))
503503
{
504504
const data_t payload = parse_hex_string(j.at("rawDataHex").get<std::string>(), "rawDataHex");
505505
if (subtype_from_data_or_throw(wrap_payload(payload)) != subtype)
@@ -663,9 +663,9 @@ namespace tivars::TypeHandlers
663663
payload.push_back(unknownAfterWord[0]);
664664
payload.push_back(static_cast<uint8_t>(j.value("nameOffsetUnits", 0) & 0xFF));
665665

666-
if (j.contains("dataHex"))
666+
if (j.contains("rawDataHex"))
667667
{
668-
vector_append(payload, parse_hex_string(j.at("dataHex").get<std::string>(), "dataHex"));
668+
vector_append(payload, parse_hex_string(j.at("rawDataHex").get<std::string>(), "rawDataHex"));
669669
}
670670
}
671671
else
@@ -968,7 +968,10 @@ namespace tivars::TypeHandlers
968968
titles.push_back(title);
969969
}
970970
out["titles"] = titles;
971-
out["rawDataHex"] = to_hex_string(payload);
971+
if (!out.contains("rawDataHex"))
972+
{
973+
out["rawDataHex"] = to_hex_string(payload);
974+
}
972975
return out;
973976
}
974977

@@ -1042,7 +1045,7 @@ namespace tivars::TypeHandlers
10421045
const uint8_t nameOffsetUnits = read_u8(payload, pos, "nameOffsetUnits");
10431046
out["nameOffsetUnits"] = nameOffsetUnits;
10441047
out["nameOffset"] = static_cast<uint16_t>(21 * nameOffsetUnits);
1045-
out["dataHex"] = to_hex_string(data_t(payload.begin() + static_cast<ptrdiff_t>(pos), payload.end()));
1048+
out["rawDataHex"] = to_hex_string(data_t(payload.begin() + static_cast<ptrdiff_t>(pos), payload.end()));
10461049
}
10471050
else
10481051
{
@@ -1105,7 +1108,10 @@ namespace tivars::TypeHandlers
11051108
throw std::invalid_argument("Invalid CabriJrAppVar variant");
11061109
}
11071110

1108-
out["rawDataHex"] = to_hex_string(payload);
1111+
if (!out.contains("rawDataHex"))
1112+
{
1113+
out["rawDataHex"] = to_hex_string(payload);
1114+
}
11091115
return out;
11101116
}
11111117

tests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ int main(int argc, char** argv)
291291
assert(flashAppJSON["blocks"].size() == 78);
292292
assert(flashAppJSON["blocks"][0]["address"] == "0000");
293293
assert(flashAppJSON["blocks"][0]["blockType"] == "02");
294-
assert(flashAppJSON["blocks"][0]["dataHex"] == "0000");
294+
assert(flashAppJSON["blocks"][0]["rawDataHex"] == "0000");
295295

296296
TIFlashFile flashAppCE = TIFlashFile::loadFromFile("testData/SmartPad.8ek");
297297
const json flashAppCEJSON = json::parse(flashAppCE.getReadableContent());
@@ -342,9 +342,9 @@ int main(int argc, char** argv)
342342
"productId": 10,
343343
"hasChecksum": true,
344344
"blocks": [
345-
{"address": "0000", "blockType": "02", "dataHex": "0000"},
346-
{"address": "4000", "blockType": "00", "dataHex": "01020304"},
347-
{"address": "0000", "blockType": "01", "dataHex": ""}
345+
{"address": "0000", "blockType": "02", "rawDataHex": "0000"},
346+
{"address": "4000", "blockType": "00", "rawDataHex": "01020304"},
347+
{"address": "0000", "blockType": "01", "rawDataHex": ""}
348348
]
349349
})");
350350
multiFlash.addHeader(TIVarType{"OperatingSystem"}, "BASE", TIModel{"84+CE"}, true);
@@ -358,7 +358,7 @@ int main(int argc, char** argv)
358358
"devices": [{"deviceType": 115, "typeId": 35}],
359359
"productId": 19,
360360
"hasChecksum": true,
361-
"calcDataHex": "01020304A0"
361+
"rawDataHex": "01020304A0"
362362
})", 1);
363363
const std::string multiFlashPath = multiFlash.saveToFile("/tmp/tivars_lib_cpp_multi_flash.8ek");
364364
TIFlashFile reloadedMultiFlash = TIFlashFile::loadFromFile(multiFlashPath);
@@ -1789,7 +1789,7 @@ End)";
17891789
"unknownWord": 4660,
17901790
"unknownAfterWordHex": "BB",
17911791
"nameOffsetUnits": 3,
1792-
"dataHex": "01020304"
1792+
"rawDataHex": "01020304"
17931793
})");
17941794
const json cabriFileJSON = json::parse(cabriFile.getReadableContent());
17951795
assert(cabriFileJSON["typeName"] == "CabriJrAppVar");
@@ -1801,7 +1801,7 @@ End)";
18011801
assert(cabriFileJSON["unknownAfterWordHex"] == "BB");
18021802
assert(cabriFileJSON["nameOffsetUnits"] == 3);
18031803
assert(cabriFileJSON["nameOffset"] == 63);
1804-
assert(cabriFileJSON["dataHex"] == "01020304");
1804+
assert(cabriFileJSON["rawDataHex"] == "01020304");
18051805

18061806
TIVarFile genericCabriFile = TIVarFile::createNew("AppVar", "GCBF", "83PCE");
18071807
genericCabriFile.setContentFromString(cabriFile.getReadableContent());

0 commit comments

Comments
 (0)