Base64.h algorithm cstddef InputArchive.h OutputArchive.h terse //CopyrightEpicGames,Inc.AllRightsReserved. #pragmaonce #ifdef_MSC_VER #pragmawarning(push) #pragmawarning(disable:43654987) #endif #include<algorithm> #include<cstddef> #ifdef_MSC_VER #pragmawarning(pop) #endif namespaceterse{ staticconstchar*alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; constexprstd::size_tbase64encode(std::size_tsize){ return((4ul*size/3ul)+3ul)&~3ul; } //destinationshouldbeoflength((4*size/3)+3)&~3 inlinestd::size_tbase64encode(char*destination,constchar*source,std::size_tsize){ char*out=destination; intval=0; intvalb=-6; for(std::size_tpos={};pos<size;++pos){ constautoc=static_cast<unsignedchar>(source[pos]); val=(val<<8)+c; valb+=8; while(valb>=0){ *out++=(alphabet[(val>>valb)&0x3F]); valb-=6; } } if(valb>-6){ *out++=alphabet[((val<<8)>>(valb+8))&0x3F]; } while(static_cast<std::size_t>(out-destination)%4){ *out++='='; } //Lengthofbase64encodeddata returnstatic_cast<std::size_t>(out-destination); } constexprstd::size_tbase64decode(std::size_tsize){ return(size*3ul)/4ul; } //destinationshouldbeoflength(size/4)*3 inlinestd::size_tbase64decode(char*destination,constchar*source,std::size_tsize){ char*out=destination; intbuffer[256]; std::fill_n(buffer,256,-1); for(inti=0;i<64;i++){ buffer[static_cast<std::size_t>(alphabet[i])]=i; } intval=0; intvalb=-8; for(std::size_tpos={};pos<size;++pos){ constautoc=static_cast<unsignedchar>(source[pos]); if(buffer[c]==-1){ break; } val=(val<<6)+buffer[c]; valb+=6; if(valb>=0){ *out++=static_cast<char>((val>>valb)&0xFF); valb-=8; } } //Lengthofbase64decodeddata returnstatic_cast<std::size_t>(out-destination); } }//namespaceterse