Skip to content

Commit 91f9f95

Browse files
committed
WIP: json header using _hex
1 parent 5fc3b82 commit 91f9f95

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

cmake/script/GenerateHeaderFromJson.cmake

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
cmake_path(GET JSON_SOURCE_PATH STEM json_source_basename)
66

77
file(READ ${JSON_SOURCE_PATH} hex_content HEX)
8-
string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
9-
string(REGEX REPLACE "[^\n][^\n]" "'\\\\x\\0'," formatted_bytes "${formatted_bytes}")
8+
string(STRIP "${hex_content}" hex_content)
109

1110
set(header_content
12-
"#include <string_view>
11+
"#include <util/strencodings.h>
12+
13+
#include <string_view>
14+
#include <cstddef>
15+
16+
using namespace util::hex_literals;
1317
1418
namespace json_tests {
15-
inline constexpr char detail_${json_source_basename}_bytes[] {
16-
${formatted_bytes}
17-
};
19+
inline auto detail_${json_source_basename}_bytes = \"${hex_content}\"_hex;
1820
19-
inline constexpr std::string_view ${json_source_basename}{std::begin(detail_${json_source_basename}_bytes), std::end(detail_${json_source_basename}_bytes)};
21+
inline std::string_view ${json_source_basename}{reinterpret_cast<const char*>(detail_${json_source_basename}_bytes.data()), detail_${json_source_basename}_bytes.size()};
2022
}
2123
")
24+
2225
file(WRITE ${HEADER_PATH} "${header_content}")

src/univalue/test/unitester.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void runtest(std::string filename, const std::string& jdata)
9797
}
9898

9999
#define TEST_FILE(name) {#name, json_tests::name}
100-
inline constexpr std::array tests{std::to_array<std::tuple<std::string_view, std::string_view>>({
100+
inline std::array tests{std::to_array<std::tuple<std::string_view, std::string_view>>({
101101
TEST_FILE(fail1),
102102
TEST_FILE(fail10),
103103
TEST_FILE(fail11),

0 commit comments

Comments
 (0)