encode.h
Go to the documentation of this file.
1 // :mode=c++:
2 /*
3 encode.h - c++ wrapper for a base64 encoding algorithm
4 
5 This is part of the libb64 project, and has been placed in the public domain.
6 For details, see http://sourceforge.net/projects/libb64
7 */
8 #ifndef BASE64_ENCODE_H
9 #define BASE64_ENCODE_H
10 
11 #include "xmlrpcpp/XmlRpcDecl.h"
12 
13 #include <iostream>
14 
15 namespace base64
16 {
17  extern "C"
18  {
19  #include "cencode.h"
20  }
21 
23  {
26 
27  encoder(int buffersize_in = 512)
28  : _buffersize(buffersize_in)
29  {
30  base64_init_encodestate(&_state);
31  }
32 
33  int encode(char value_in)
34  {
35  return base64_encode_value(value_in);
36  }
37 
38  int encode(const char* code_in, const int length_in, char* plaintext_out)
39  {
40  return base64_encode_block(code_in, length_in, plaintext_out, &_state);
41  }
42 
43  int encode_end(char* plaintext_out)
44  {
45  return base64_encode_blockend(plaintext_out, &_state);
46  }
47 
48  void encode(std::istream& istream_in, std::ostream& ostream_in)
49  {
50  base64_init_encodestate(&_state);
51  //
52  const int N = _buffersize;
53  char* plaintext = new char[N];
54  char* code = new char[2*N];
55  int plainlength;
56  int codelength;
57 
58  do
59  {
60  istream_in.read(plaintext, N);
61  plainlength = istream_in.gcount();
62  //
63  codelength = encode(plaintext, plainlength, code);
64  ostream_in.write(code, codelength);
65  }
66  while (istream_in.good() && plainlength > 0);
67 
68  codelength = encode_end(code);
69  ostream_in.write(code, codelength);
70  //
71  base64_init_encodestate(&_state);
72 
73  delete [] code;
74  delete [] plaintext;
75  }
76  };
77 
78 } // namespace base64
79 
80 #endif // BASE64_ENCODE_H
81 
base64_encodestate
Definition: cencode.h:16
base64::encoder::_state
base64_encodestate _state
Definition: encode.h:24
base64_encode_block
int base64_encode_block(const char *plaintext_in, int length_in, char *code_out, base64_encodestate *state_in)
Definition: cencode.c:26
cencode.h
XmlRpcDecl.h
base64::encoder::encode
void encode(std::istream &istream_in, std::ostream &ostream_in)
Definition: encode.h:48
base64
Definition: decode.h:15
base64_encode_value
char base64_encode_value(char value_in)
Definition: cencode.c:19
base64::encoder::_buffersize
int _buffersize
Definition: encode.h:25
base64::encoder::encode
int encode(const char *code_in, const int length_in, char *plaintext_out)
Definition: encode.h:38
base64::encoder::encode_end
int encode_end(char *plaintext_out)
Definition: encode.h:43
base64_init_encodestate
void base64_init_encodestate(base64_encodestate *state_in)
Definition: cencode.c:12
base64::encoder::encoder
encoder(int buffersize_in=512)
Definition: encode.h:27
base64_encode_blockend
int base64_encode_blockend(char *code_out, base64_encodestate *state_in)
Definition: cencode.c:89
base64::encoder::encode
int encode(char value_in)
Definition: encode.h:33
XMLRPCPP_DECL
#define XMLRPCPP_DECL
Definition: XmlRpcDecl.h:52
base64::encoder
Definition: encode.h:22


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:32