MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / Base64Encode

Function Base64Encode

net/utils.cpp:132–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132void Base64Encode(std::string_view in, std::string &out) {
133 auto main = in.size() / 3;
134 auto remain = in.size() % 3;
135 if (0 == remain) {
136 remain = 3;
137 main--;
138 }
139 auto out_size = (main + 1) * 4;
140 out.resize(out_size);
141 auto _in = &in[0];
142 auto _out = &out[0];
143 auto end = _in + main * 3;
144
145 for (; _in + 3 * 4 < end; _in += 3 * 4, _out += 4 * 4) {
146 base64_translate_3to4(_in, _out);
147 base64_translate_3to4(_in + 3, _out + 4);
148 base64_translate_3to4(_in + 6, _out + 8);
149 base64_translate_3to4(_in + 9, _out + 12);
150 }
151
152 for (; _in < end; _in += 3, _out += 4) {
153 base64_translate_3to4(_in, _out);
154 }
155
156 char itail[4] = {0};
157 itail[0] = _in[0];
158 if (remain == 2) {
159 itail[1] = _in[1];
160 } else if (remain == 3) {
161 *(short *)&itail[1] = *(short *)&_in[1];
162 }
163 base64_translate_3to4(itail, _out);
164 for (size_t i = 0; i < (3 - remain); ++i) out[out_size - i - 1] = '=';
165}
166
167static bool do_zerocopy_available() {
168 int result = 0;

Callers 4

md5_base64Function · 0.85
sign_v1Method · 0.85
set_proxyMethod · 0.85
TESTFunction · 0.85

Calls 3

base64_translate_3to4Function · 0.85
sizeMethod · 0.45
resizeMethod · 0.45

Tested by 1

TESTFunction · 0.68