46const char Base64Encoder<T>::enc64[65]=
47 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
48 "abcdefghijklmnopqrstuvwxyz0123456789+/";
53 charFullLength(fullLength_ * sizeof(T)),
61 const unsigned char* charData =
reinterpret_cast<const unsigned char*
>(data);
62 size_t charLength = length *
sizeof(T);
66 fillOverflow(charData, charLength, pos);
67 while (pos+3 <= charLength) {
68 encodeBlock(charData+pos);
71 fillOverflow(charData, charLength, pos);
72 numWritten += charLength;
73 if (numWritten == charFullLength) {
81 while (numOverflow < 3 && pos < charLength) {
82 overflow[numOverflow] = charData[pos];
86 if (numOverflow == 3) {
87 encodeBlock(overflow);
93void Base64Encoder<T>::flushOverflow()
95 if (numOverflow > 0) {
96 for (
int iOverflow = numOverflow; iOverflow<3; ++iOverflow) {
97 overflow[iOverflow] = 0;
99 encodeUnfinishedBlock(overflow, numOverflow);
105void Base64Encoder<T>::encodeBlock(
const unsigned char* data)
107 ostr << enc64[ data[0] >> 2 ];
108 ostr << enc64[ ((data[0] & 0x03) << 4) | ((data[1] & 0xf0) >> 4) ];
109 ostr << (
unsigned char) (enc64[ ((data[1] & 0x0f) << 2) | ((data[2] & 0xc0) >> 6) ]);
110 ostr << (
unsigned char) (enc64[ data[2] & 0x3f ]);
114void Base64Encoder<T>::encodeUnfinishedBlock(
const unsigned char* data,
int length )
116 ostr << enc64[ data[0] >> 2 ];
117 ostr << enc64[ ((data[0] & 0x03) << 4) | ((data[1] & 0xf0) >> 4) ];
118 ostr << (
unsigned char) (
120 enc64[ ((data[1] & 0x0f) << 2) | ((data[2] & 0xc0) >> 6) ] :
123 ostr << (
unsigned char) (
'=' );
130const char Base64Decoder<T>::dec64[82]=
131 "|###}rstuvwxyz{#######>?@"\
132 "ABCDEFGHIJKLMNOPQRSTUVW######XYZ"\
133 "[\\]^_`abcdefghijklmnopq";
139 charFullLength(fullLength_ * sizeof(T)),
147 unsigned char* charData =
reinterpret_cast<unsigned char*
>(data);
148 size_t charLength = length *
sizeof(T);
152 flushOverflow(charData, charLength, pos);
153 while (pos+3 <= charLength) {
154 decodeBlock(charData+pos);
157 if (pos < charLength) {
158 decodeBlock(overflow);
160 flushOverflow(charData, charLength, pos);
162 numRead += charLength;
168 while (posOverflow < 3 && pos < charLength) {
169 charData[pos] = overflow[posOverflow];
176unsigned char Base64Decoder<T>::getNext()
178 unsigned char nextChar;
180 return (
unsigned char) (dec64[nextChar - 43] - 62);
184void Base64Decoder<T>::decodeBlock(
unsigned char* data)
186 unsigned char input[4];
187 input[0] = getNext();
188 input[1] = getNext();
189 input[2] = getNext();
190 input[3] = getNext();
191 data[0] = (
unsigned char) (input[0] << 2 | input[1] >> 4);
192 data[1] = (
unsigned char) (input[1] << 4 | input[2] >> 2);
193 data[2] = (
unsigned char) (((input[2] << 6) & 0xc0) | input[3]);
Base64Decoder(std::istream &istr_, size_t fullLength_)
void decode(T *data, size_t length)
Base64Encoder(std::ostream &ostr_, size_t fullLength_)
void encode(const T *data, size_t length)
Top level namespace for all of OpenLB.
#define OLB_PRECONDITION(COND)