#include <base64_writer.h>
Collaboration diagram for Base64Writer:

Public Member Functions | |
| Base64Writer () | |
| void | ClearBuffer () |
| empty temporary buffer | |
| void | CreateHeader () |
| this is used to allocate the memory for the final count of bytes | |
| int | Decode (char c0, char c1, char c2, char c3, char *r0, char *r1, char *r2) |
| decode 3 bytes from 4 Base64 bytes (4/3 ratio) | |
| void | DumpToFile () |
| when all stream is ready buffer is sent to file | |
| void | finish () |
| notify that we don't want to add any data. Closing the current buffer | |
| void | PushByteInBase64 (unsigned char c) |
| push to file a Byte | |
| void | PushDoubleInBase64 (double c) |
| push to file a double | |
| void | PushIntegerInBase64 (int c) |
| push to file an integer | |
| void | PushStrInBase64 (char *c) |
| push to file a string | |
| void | SetOutputFile (LMFile &f) |
| set the output file to use | |
| void | WriteHeader () |
| for any packet in base64 a little header is used that is an int = nbBytes written | |
Private Member Functions | |
| void | dumpToBuffer () |
| when 4 bytes are ready they are dumped to buffer by this function | |
| void | InitBase64Stuff () |
| initialisation process | |
Private Attributes | |
| std::vector< unsigned char > | buffer |
| buffer to cache data | |
| char | dtable [256] |
| decoding table | |
| char | etable [256] |
| encoding table | |
| LMFile | file |
| LM file descriptor. | |
| unsigned char | igroup [3] |
| used to code/decode | |
| int | linelength |
| unused | |
| int | maxlinelength |
| unused | |
| int | n |
| stage in conversion process(1,2 or 3) | |
| long | nbBytes |
| number of bytes written to buffer | |
| unsigned char | ogroup [4] |
| int | start |
| for rewind need o floating index | |
Definition at line 57 of file base64_writer.h.
| Base64Writer::Base64Writer | ( | ) | [inline] |
Definition at line 61 of file base64_writer.h.
References InitBase64Stuff(), linelength, n, and start.
00061 { 00062 linelength = 0; 00063 InitBase64Stuff(); 00064 n = 0; 00065 start = -1; 00066 };
Here is the call graph for this function:

| void Base64Writer::ClearBuffer | ( | ) | [inline] |
empty temporary buffer
Definition at line 352 of file base64_writer.h.
References buffer, and nbBytes.
Referenced by CreateHeader(), and DumperReprise< Domain, Dim >::DumpField().
| void Base64Writer::CreateHeader | ( | ) | [inline] |
this is used to allocate the memory for the final count of bytes
Definition at line 357 of file base64_writer.h.
References ClearBuffer(), and PushIntegerInBase64().
Referenced by ParaviewHelper::startCellDataList(), ParaviewHelper::startCellsConnectivityList(), ParaviewHelper::startCellsoffsetsList(), ParaviewHelper::startCellstypesList(), ParaviewHelper::startData(), and ParaviewHelper::startDofList().
00357 { 00358 ClearBuffer(); 00359 PushIntegerInBase64(0); 00360 }
Here is the call graph for this function:

| int Base64Writer::Decode | ( | char | c0, | |
| char | c1, | |||
| char | c2, | |||
| char | c3, | |||
| char * | r0, | |||
| char * | r1, | |||
| char * | r2 | |||
| ) | [inline] |
decode 3 bytes from 4 Base64 bytes (4/3 ratio)
Definition at line 255 of file base64_writer.h.
References DBG_ALL, dtable, and DUMP.
Referenced by WriteHeader().
00256 { 00257 00258 unsigned char d0, d1, d2, d3; 00259 00260 d0 = dtable[0+c0]; 00261 d1 = dtable[0+c1]; 00262 d2 = dtable[0+c2]; 00263 d3 = dtable[0+c3]; 00264 00265 00266 00267 DUMP("d0 " << (int)d0 << " d1 " << (int)d1 << " d2 " << (int)d2 << " d3 " << (int)d3,DBG_ALL); 00268 00269 // Decode the 3 bytes 00270 00271 *r0 = ((d0 << 2) & 0xFC) | ((d1 >> 4) & 0x03); 00272 *r1 = ((d1 << 4) & 0xF0) | ((d2 >> 2) & 0x0F); 00273 *r2 = ((d2 << 6) & 0xC0) | ((d3 >> 0) & 0x3F); 00274 00275 DUMP("r0 " << (int)*r0 << " r1 " << (int)*r1 << " r2 " << (int)*r2,DBG_ALL); 00276 00277 // Return the number of bytes actually decoded 00278 00279 if (c2 == '=') 00280 { 00281 return 1; 00282 } 00283 if (c3 == '=') 00284 { 00285 return 2; 00286 } 00287 return 3; 00288 }
| void Base64Writer::dumpToBuffer | ( | ) | [inline, private] |
when 4 bytes are ready they are dumped to buffer by this function
Definition at line 208 of file base64_writer.h.
References buffer, DBG_ALL, DUMP, etable, igroup, n, ogroup, and start.
Referenced by finish(), and PushByteInBase64().
00208 { 00209 if(n<3){ 00210 igroup[2]= 0; 00211 if(n<2){ 00212 igroup[1]= 0; 00213 } 00214 } 00215 00216 DUMP("premiere partie en base 64 : " << (igroup[0]>>2),DBG_ALL); 00217 ogroup[0]= etable[igroup[0]>>2]; 00218 DUMP("deuxieme partie en base 64 : " << (((igroup[0]&3)<<4)|(igroup[1]>>4)),DBG_ALL); 00219 ogroup[1]= etable[((igroup[0]&3)<<4)|(igroup[1]>>4)]; 00220 DUMP("troisieme partie en base 64 : " << (((igroup[1]&0xF)<<2)|(igroup[2]>>6)),DBG_ALL); 00221 ogroup[2]= etable[((igroup[1]&0xF)<<2)|(igroup[2]>>6)]; 00222 DUMP("last partie en base 64 : " << (igroup[2]&0x3F),DBG_ALL); 00223 ogroup[3]= etable[igroup[2]&0x3F]; 00224 00225 if(n<3){ 00226 ogroup[3]= '='; 00227 if(n<2){ 00228 ogroup[2]= '='; 00229 } 00230 } 00231 00232 for(int i= 0;i<4;i++){ 00233 DUMP("dumped to buffer " << ogroup[i],DBG_ALL); 00234 if (start == -1) 00235 buffer.push_back(ogroup[i]); 00236 else{ 00237 buffer[start] = ogroup[i]; 00238 ++start; 00239 } 00240 } 00241 00242 //remise a zero du compteur 00243 n = 0; 00244 }
| void Base64Writer::DumpToFile | ( | ) | [inline] |
when all stream is ready buffer is sent to file
Definition at line 348 of file base64_writer.h.
References buffer, file, and LMFile::write().
Referenced by DumperReprise< Domain, Dim >::DumpField(), and WriteHeader().
Here is the call graph for this function:

| void Base64Writer::finish | ( | ) | [inline] |
notify that we don't want to add any data. Closing the current buffer
Definition at line 201 of file base64_writer.h.
References dumpToBuffer(), linelength, and n.
Referenced by WriteHeader().
00201 { 00202 if (n == 0) return; 00203 00204 dumpToBuffer(); 00205 linelength = 0; 00206 }
Here is the call graph for this function:

| void Base64Writer::InitBase64Stuff | ( | ) | [inline, private] |
initialisation process
Definition at line 131 of file base64_writer.h.
References dtable, and etable.
Referenced by Base64Writer().
00131 { 00132 memset(dtable,0xFF,256); 00133 memset(etable,0xFF,256); 00134 00135 for(int i=0;i<9;i++){ 00136 etable[i]= 'A'+i; 00137 dtable[0+etable[i]] = i; 00138 etable[i+9]= 'J'+i; 00139 dtable[0+etable[i+9]] = i+9; 00140 etable[26+i]= 'a'+i; 00141 dtable[0+etable[26+i]] = i + 26; 00142 etable[26+i+9]= 'j'+i; 00143 dtable[0+etable[26+i+9]] = i + 26 + 9; 00144 } 00145 for(int i= 0;i<8;i++){ 00146 etable[i+18]= 'S'+i; 00147 dtable[0+etable[i+18]] = i + 18; 00148 etable[26+i+18]= 's'+i; 00149 dtable[0+etable[26+i+18]] = 26 + i + 18; 00150 } 00151 for(int i= 0;i<10;i++){ 00152 etable[52+i]= '0'+i; 00153 dtable[0+etable[i+52]] = i + 52; 00154 } 00155 etable[62]= '+'; 00156 dtable[0+etable[62]] = 62; 00157 etable[63]= '/'; 00158 dtable[0+etable[63]] = 63; 00159 }
| void Base64Writer::PushByteInBase64 | ( | unsigned char | c | ) | [inline] |
push to file a Byte
Definition at line 187 of file base64_writer.h.
References DBG_ALL, DUMP, dumpToBuffer(), igroup, n, and nbBytes.
Referenced by PushDoubleInBase64(), PushIntegerInBase64(), PushStrInBase64(), and WriteHeader().
00187 { 00188 //initialise les blocs 00189 DUMP("pushing byte " << (int) c << " at position " << n,DBG_ALL); 00190 00191 if (n == 0){igroup[0]= igroup[1]= igroup[2]= 0;} 00192 igroup[n]= c; 00193 ++n; 00194 00195 if(n == 3){ 00196 dumpToBuffer(); 00197 } 00198 nbBytes += 1; 00199 }
Here is the call graph for this function:

| void Base64Writer::PushDoubleInBase64 | ( | double | c | ) | [inline] |
push to file a double
Definition at line 178 of file base64_writer.h.
References DBG_ALL, DUMP, and PushByteInBase64().
Referenced by DumperReprise< Domain, Dim >::DumpField(), and ParaviewHelper::pushDouble().
00178 { 00179 DUMP("pushing double " << d << " as " << sizeof(double) << " bytes",DBG_ALL); 00180 00181 unsigned char * c = (unsigned char*)&d; 00182 for (unsigned int i = 0 ; i < sizeof(double) ; ++i){ 00183 PushByteInBase64(c[i]); 00184 } 00185 }
Here is the call graph for this function:

| void Base64Writer::PushIntegerInBase64 | ( | int | c | ) | [inline] |
push to file an integer
Definition at line 161 of file base64_writer.h.
References DBG_ALL, DUMP, n, and PushByteInBase64().
Referenced by CreateHeader(), ParaviewHelper::pushInteger(), and WriteHeader().
00161 { 00162 DUMP("pushing " << d << " ( n = " << n << " )",DBG_ALL); 00163 unsigned char * c = (unsigned char*)&d; 00164 for (unsigned int i = 0 ; i < sizeof(int) ; ++i){ 00165 PushByteInBase64(c[i]); 00166 } 00167 }
Here is the call graph for this function:

| void Base64Writer::PushStrInBase64 | ( | char * | c | ) | [inline] |
push to file a string
Definition at line 169 of file base64_writer.h.
References PushByteInBase64().
00169 { 00170 00171 unsigned char * c = (unsigned char*)str; 00172 for (unsigned int i = 0 ; i < 512 ; ++i){ 00173 if (str[i] == '\0') break; 00174 PushByteInBase64(c[i]); 00175 } 00176 }
Here is the call graph for this function:

| void Base64Writer::SetOutputFile | ( | LMFile & | f | ) | [inline] |
set the output file to use
Definition at line 92 of file base64_writer.h.
References file.
Referenced by DumperReprise< Domain, Dim >::Dump(), and ParaviewHelper::setOutputFile().
00092 { 00093 file = f; 00094 };
| void Base64Writer::WriteHeader | ( | ) | [inline] |
for any packet in base64 a little header is used that is an int = nbBytes written
Definition at line 291 of file base64_writer.h.
References buffer, DBG_ALL, Decode(), DUMP, DumpToFile(), finish(), nbBytes, PushByteInBase64(), PushIntegerInBase64(), and start.
Referenced by ParaviewHelper::endCellDataList(), ParaviewHelper::endCellsConnectivityList(), ParaviewHelper::endCellsoffsetsList(), ParaviewHelper::endCellstypesList(), ParaviewHelper::endData(), and ParaviewHelper::endDofList().
00291 { 00292 00293 // if (bflag == BASE64){ 00294 // char byteC[8]; 00295 char byte[6]; 00296 00297 finish(); 00298 00299 /* long save_offset; */ 00300 00301 00302 /* save_offset = file.tell(); */ 00303 /* file.seek(header_offset,SEEK_SET); */ 00304 /* //reread the 4 bytes precedently written */ 00305 00306 /* file.read(byteC,sizeof(char),4); */ 00307 00308 /* DUMP("la chaine saisie " << byteC[0] << " " << byteC[1] << " " << byteC[2] << " " << byteC[3]); */ 00309 /* b64.Decode(byteC[0],byteC[0],byteC[0],byteC[0], */ 00310 /* byte,byte+1,byte+2); */ 00311 DUMP("la chaine saisie " << buffer[0] << " " << buffer[1] << " " << buffer[2] << " " << buffer[3],DBG_ALL); 00312 Decode(buffer[0],buffer[0],buffer[0],buffer[0], 00313 byte,byte+1,byte+2); 00314 00315 /* file.read(byteC+4,sizeof(char),4); */ 00316 /* DUMP("la chaine saisie " << byteC[4] << " " << byteC[5] << " " << byteC[6] << " " << byteC[7]); */ 00317 /* int nb = b64.Decode(byteC[4],byteC[5],byteC[6],byteC[7], */ 00318 /* byte+3,byte+4,byte+5); */ 00319 00320 DUMP("la chaine saisie " << buffer[4] << " " << buffer[5] << " " << buffer[6] << " " << buffer[7],DBG_ALL); 00321 int nb = Decode(buffer[4],buffer[5],buffer[6],buffer[7], 00322 byte+3,byte+4,byte+5); 00323 00324 00325 /* //je me replace au debut du header */ 00326 /* file.seek(header_offset,SEEK_SET); */ 00327 /* //je viens de relire 6 octets */ 00328 /* //les quatres premiers seulement sont a changer */ 00329 00330 00331 DUMP("placing number of writen bytes : " << nbBytes << " " << buffer.size(),DBG_ALL); 00332 00333 int temp = nbBytes; 00334 start = 0; 00335 PushIntegerInBase64(temp); 00336 if (nb > 1) 00337 PushByteInBase64(byte[4]); 00338 if (nb > 2) 00339 PushByteInBase64(byte[5]); 00340 00341 start = -1; 00342 nbBytes = temp; 00343 00344 finish(); 00345 DumpToFile(); 00346 }
Here is the call graph for this function:

std::vector<unsigned char> Base64Writer::buffer [private] |
buffer to cache data
Definition at line 122 of file base64_writer.h.
Referenced by ClearBuffer(), dumpToBuffer(), DumpToFile(), and WriteHeader().
char Base64Writer::dtable[256] [private] |
decoding table
Definition at line 105 of file base64_writer.h.
Referenced by Decode(), and InitBase64Stuff().
char Base64Writer::etable[256] [private] |
encoding table
Definition at line 107 of file base64_writer.h.
Referenced by dumpToBuffer(), and InitBase64Stuff().
LMFile Base64Writer::file [private] |
LM file descriptor.
Definition at line 119 of file base64_writer.h.
Referenced by DumpToFile(), and SetOutputFile().
unsigned char Base64Writer::igroup[3] [private] |
used to code/decode
Definition at line 111 of file base64_writer.h.
Referenced by dumpToBuffer(), and PushByteInBase64().
int Base64Writer::linelength [private] |
int Base64Writer::maxlinelength [private] |
int Base64Writer::n [private] |
stage in conversion process(1,2 or 3)
Definition at line 109 of file base64_writer.h.
Referenced by Base64Writer(), dumpToBuffer(), finish(), PushByteInBase64(), and PushIntegerInBase64().
long Base64Writer::nbBytes [private] |
number of bytes written to buffer
Definition at line 124 of file base64_writer.h.
Referenced by ClearBuffer(), PushByteInBase64(), and WriteHeader().
unsigned char Base64Writer::ogroup[4] [private] |
int Base64Writer::start [private] |
for rewind need o floating index
Definition at line 126 of file base64_writer.h.
Referenced by Base64Writer(), dumpToBuffer(), and WriteHeader().
1.5.2