MCPcopy Create free account
hub / github.com/catboost/catboost / EmitHex

Function EmitHex

tools/rescompiler/main.cpp:28–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26using namespace NResource;
27
28static inline void EmitHex(IOutputStream& stream, const TString& view) {
29 const unsigned char* data = reinterpret_cast<const unsigned char*>(view.data());
30 size_t len = view.size();
31
32 constexpr size_t CHAR2HEX = 5; // len('0x??,') == 5
33 constexpr size_t MAX_STEP = 16;
34 constexpr size_t STEPS[] = {MAX_STEP, 1};
35
36 auto print = [](char* out, const unsigned char* iter, const unsigned char* end) {
37 char templ[CHAR2HEX + 1] = "0x??,";
38 while (iter != end) {
39 HexEncode(iter, 1ULL, templ + 2ULL);
40 memcpy(out, templ, CHAR2HEX);
41 iter++;
42 out += CHAR2HEX;
43 }
44 };
45
46 char buf[CHAR2HEX * MAX_STEP + 4] = {};
47 for (size_t step : STEPS) {
48 while (len >= step) {
49 print(buf, data, data + step);
50 buf[CHAR2HEX * step] = 0;
51 len -= step;
52 data += step;
53 stream << buf << (step > 1 ? "\n" : "");
54 }
55 }
56 stream << '\n';
57}
58
59static inline void EmitHexArray(const TString& data, const TString& varName, IOutputStream& out) {
60 const TString c = Compress(data);

Callers 1

EmitHexArrayFunction · 0.85

Calls 4

HexEncodeFunction · 0.50
printFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected