MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / base64_decode

Function base64_decode

examples/server/server.cpp:76–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76static std::vector<uint8_t> base64_decode(std::string const &encoded_string)
77{
78 int i = 0;
79 int j = 0;
80 int in_ = 0;
81
82 int in_len = encoded_string.size();
83
84 uint8_t char_array_4[4];
85 uint8_t char_array_3[3];
86
87 std::vector<uint8_t> ret;
88
89 while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_]))
90 {
91 char_array_4[i++] = encoded_string[in_]; in_++;
92 if (i == 4)
93 {
94 for (i = 0; i <4; i++)
95 {
96 char_array_4[i] = base64_chars.find(char_array_4[i]);
97 }
98
99 char_array_3[0] = ((char_array_4[0] ) << 2) + ((char_array_4[1] & 0x30) >> 4);
100 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
101 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
102
103 for (i = 0; (i < 3); i++)
104 {
105 ret.push_back(char_array_3[i]);
106 }
107 i = 0;
108 }
109 }
110
111 if (i)
112 {
113 for (j = i; j <4; j++)
114 {
115 char_array_4[j] = 0;
116 }
117
118 for (j = 0; j <4; j++)
119 {
120 char_array_4[j] = base64_chars.find(char_array_4[j]);
121 }
122
123 char_array_3[0] = ((char_array_4[0] ) << 2) + ((char_array_4[1] & 0x30) >> 4);
124 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
125 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
126
127 for (j = 0; (j < i - 1); j++)
128 {
129 ret.push_back(char_array_3[j]);
130 }
131 }
132
133 return ret;

Callers 1

launch_slot_with_dataMethod · 0.70

Calls 4

findMethod · 0.80
is_base64Function · 0.70
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected