WvStreams
wvbase64ex.cc
1/*
2 * A WvBase64 example.
3 *
4 */
5
6#include "wvbase64.h"
7#include "wvstream.h"
8#include "wvistreamlist.h"
9#include "wvencoderstream.h"
10#include "wvbufbase.h"
11
12int main()
13{
14 WvEncoder *enc;
15 enc = new WvBase64Encoder();
16
17 WvInPlaceBuf to_encode(100);
18 WvInPlaceBuf encoded(100);
19
20 to_encode.put("123",3);
21 // to_encode contains the string to be encoded in base64
22
23 if (enc->encode(to_encode, encoded, true,true))
24 printf ("This is the result: %s\n", (char *) encoded.get(1));
25
26 // Displayed on screen:
27 // This is the result: MTIz
28
29
30 WvEncoder *dec;
31 dec = new WvBase64Decoder();
32
33 WvInPlaceBuf to_decode(100);
34 WvInPlaceBuf decoded(100);
35
36 to_decode.put("MTIz",4);
37 // to_encode contains the string to be encoded in base64
38
39 if (dec->encode(to_decode, decoded, true))
40 printf ("This is the result: %s\n", (char *) decoded.get(1));
41
42 // Displayed on screen:
43 // This is the result: 123
44
45 return 0;
46}
A base 64 decoder.
Definition wvbase64.h:50
A base 64 encoder.
Definition wvbase64.h:21
The base encoder class.
Definition wvencoder.h:68
bool encode(WvBuf &inbuf, WvBuf &outbuf, bool flush=false, bool finish=false)
Reads data from the input buffer, encodes it, and writes the result to the output buffer.
Definition wvencoder.cc:36
The in place raw memory buffer type.
Definition wvbuf.h:165