MCPcopy Create free account
hub / github.com/78/tenbox / Base64Encode

Function Base64Encode

src/daemon/runtime_manager.cpp:46–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46std::string Base64Encode(const std::vector<uint8_t>& bytes) {
47 static constexpr char kAlphabet[] =
48 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
49 std::string out;
50 out.reserve(((bytes.size() + 2) / 3) * 4);
51 for (size_t i = 0; i < bytes.size(); i += 3) {
52 const uint32_t b0 = bytes[i];
53 const uint32_t b1 = i + 1 < bytes.size() ? bytes[i + 1] : 0;
54 const uint32_t b2 = i + 2 < bytes.size() ? bytes[i + 2] : 0;
55 const uint32_t value = (b0 << 16) | (b1 << 8) | b2;
56 out.push_back(kAlphabet[(value >> 18) & 0x3f]);
57 out.push_back(kAlphabet[(value >> 12) & 0x3f]);
58 out.push_back(i + 1 < bytes.size() ? kAlphabet[(value >> 6) & 0x3f] : '=');
59 out.push_back(i + 2 < bytes.size() ? kAlphabet[value & 0x3f] : '=');
60 }
61 return out;
62}
63
64std::vector<uint8_t> HexDecode(const std::string& value) {
65 auto digit = [](char ch) -> int {

Callers 1

HandleRuntimeMessageMethod · 0.70

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected