MCPcopy Create free account
hub / github.com/BobbyAnguelov/Esoterica / Decode

Function Decode

Code/Base/Encoding/Encoding.cpp:85–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83 return (uint8_t) -1;
84 }
85
86 Blob Decode( uint8_t const* pDataToDecode, size_t dataSize )
87 {
88 EE_ASSERT( pDataToDecode != nullptr && dataSize > 0 );
89 Blob decodedData;
90
91 int32_t idx = 0;
92 size_t i = 0, j = 0;
93 uint8_t byte4[4], byte3[3];
94
95 while ( dataSize-- && ( pDataToDecode[idx] != '=' ) && IsBase64( pDataToDecode[idx] ) )
96 {
97 byte4[i++] = pDataToDecode[idx]; idx++;
98 if ( i == 4 )
99 {
100 for ( i = 0; i < 4; i++ )
101 {
102 byte4[i] = FindCharIndex( byte4[i] );
103 }
104
105 byte3[0] = ( byte4[0] << 2 ) + ( ( byte4[1] & 0x30 ) >> 4 );
106 byte3[1] = ( ( byte4[1] & 0xf ) << 4 ) + ( ( byte4[2] & 0x3c ) >> 2 );
107 byte3[2] = ( ( byte4[2] & 0x3 ) << 6 ) + byte4[3];
108
109 for ( i = 0; ( i < 3 ); i++ )
110 {
111 decodedData.emplace_back( byte3[i] );
112 }
113
114 i = 0;
115 }
116 }
117
118 //-------------------------------------------------------------------------
119
120 if ( i )
121 {
122 for ( j = i; j < 4; j++ )
123 {
124 byte4[j] = 0;
125 }
126
127 for ( j = 0; j < 4; j++ )
128 {
129 byte4[j] = FindCharIndex( byte4[j] );
130 }
131
132 byte3[0] = ( byte4[0] << 2 ) + ( ( byte4[1] & 0x30 ) >> 4 );
133 byte3[1] = ( ( byte4[1] & 0xf ) << 4 ) + ( ( byte4[2] & 0x3c ) >> 2 );
134 byte3[2] = ( ( byte4[2] & 0x3 ) << 6 ) + byte4[3];
135
136 for ( j = 0; ( j < i - 1 ); j++ )
137 {
138 decodedData.emplace_back( byte3[j] );
139 }
140 }
141
142 return decodedData;

Callers 1

CreateTextureFromBase64Function · 0.85

Calls 3

IsBase64Function · 0.85
FindCharIndexFunction · 0.85
emplace_backMethod · 0.45

Tested by

no test coverage detected