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

Method decode

common/base64.hpp:200–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198 */
199 template<typename Input_iterator, typename Output_iterator>
200 static Output_iterator decode(Input_iterator in_begin, Input_iterator in_end, Output_iterator out,
201 alphabet alphabet = alphabet::auto_,
202 decoding_behavior behavior = decoding_behavior::moderate)
203 {
204 //constexpr auto pad = '=';
205 std::uint8_t last = 0;
206 auto bits = 0;
207
208 while (in_begin != in_end) {
209 auto c = *in_begin;
210 ++in_begin;
211
212 if (c == '=') {
213 break;
214 }
215
216 auto part = _base64_value(alphabet, c);
217
218 // enough bits for one byte
219 if (bits + 6 >= 8) {
220 *out = (last << (8 - bits)) | (part >> (bits - 2));
221 ++out;
222
223 bits -= 2;
224 } else {
225 bits += 6;
226 }
227
228 last = part;
229 }
230
231 // check padding
232 if (behavior != decoding_behavior::loose) {
233 while (in_begin != in_end) {
234 auto c = *in_begin;
235 ++in_begin;
236
237 if (c != '=') {
238 throw base64_error("invalid base64 character.");
239 }
240 }
241 }
242
243 return out;
244 }
245 /**
246 Decodes a string.
247

Callers 4

generateFunction · 0.45
llamaFunction · 0.45

Calls 6

decodeFunction · 0.85
reserveMethod · 0.80
lengthMethod · 0.80
base64_errorClass · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected