MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / encode

Function encode

imperative/src/impl/utils/base64.cpp:52–90  ·  view source on GitHub ↗

* Encode string to base64 string * @param input - source string * @param outdata - target base64 string * @param linesize - max size of line */

Source from the content-addressed store, hash-verified

50 * @param linesize - max size of line
51 */
52void encode(
53 const std::vector<std::uint8_t>& input, std::vector<std::uint8_t>& outdata,
54 int linesize) {
55 outdata.clear();
56
57 unsigned char in[3], out[4];
58 int i, len, blocksout = 0;
59 size_t j = 0;
60
61 auto* indata = reinterpret_cast<const unsigned char*>(input.data());
62 unsigned int insize = input.size();
63
64 while (j <= insize) {
65 len = 0;
66 for (i = 0; i < 3; i++) {
67 in[i] = (unsigned char)indata[j];
68 j++;
69 if (j <= insize) {
70 len++;
71 } else {
72 in[i] = 0;
73 }
74 }
75 if (len) {
76 encodeblock(in, out, len);
77 for (i = 0; i < 4; i++) {
78 outdata.push_back(out[i]);
79 }
80 blocksout++;
81 }
82 if (blocksout >= (linesize / 4) || (j == insize)) {
83 if (blocksout) {
84 outdata.push_back('\r');
85 outdata.push_back('\n');
86 }
87 blocksout = 0;
88 }
89 }
90}
91
92/**
93 * Decode base64 string ot source

Callers 2

getMethod · 0.85
putMethod · 0.85

Calls 7

encodeblockFunction · 0.85
clearMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected