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

Function decode

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

* Decode base64 string ot source * @param input - base64 string * @param outdata - source string */

Source from the content-addressed store, hash-verified

95 * @param outdata - source string
96 */
97void decode(
98 const std::vector<std::uint8_t>& input, std::vector<std::uint8_t>& outdata) {
99 outdata.clear();
100
101 unsigned char in[4], out[3], v;
102 int i, len;
103 size_t j = 0;
104
105 auto* indata = reinterpret_cast<const unsigned char*>(input.data());
106 unsigned int insize = input.size();
107
108 while (j <= insize) {
109 for (len = 0, i = 0; i < 4 && (j <= insize); i++) {
110 v = 0;
111 while ((j <= insize) && v == 0) {
112 v = (unsigned char)indata[j++];
113 v = (unsigned char)((v < 43 || v > 122) ? 0 : cd64[v - 43]);
114 if (v) {
115 v = (unsigned char)((v == '$') ? 0 : v - 61);
116 }
117 }
118 if (j <= insize) {
119 len++;
120 if (v) {
121 in[i] = (unsigned char)(v - 1);
122 }
123 } else {
124 in[i] = 0;
125 }
126 }
127 if (len) {
128 decodeblock(in, out);
129 for (i = 0; i < len - 1; i++) {
130 outdata.push_back(out[i]);
131 }
132 }
133 }
134}
135
136/**
137 * Encode binary data to base64 buffer

Callers 1

getMethod · 0.85

Calls 7

decodeblockFunction · 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