Line | |
---|
1 | /**
|
---|
2 | * @file codec.h
|
---|
3 | * @author myusgun@gmail.com
|
---|
4 | * @brief codec
|
---|
5 | */
|
---|
6 | #ifndef __cf_codec_h__
|
---|
7 | #define __cf_codec_h__
|
---|
8 |
|
---|
9 | #include "cf/bin.h"
|
---|
10 | #include "cf/exception.h"
|
---|
11 |
|
---|
12 | #include <string>
|
---|
13 |
|
---|
14 | namespace cf
|
---|
15 | {
|
---|
16 | /**
|
---|
17 | * codec
|
---|
18 | */
|
---|
19 | namespace codec
|
---|
20 | {
|
---|
21 | /**
|
---|
22 | * interface
|
---|
23 | */
|
---|
24 | class ICodec
|
---|
25 | {
|
---|
26 | public:
|
---|
27 | /**
|
---|
28 | * encode(virtual)
|
---|
29 | * @return encoded string
|
---|
30 | * @param in input
|
---|
31 | * @throw cf::exception
|
---|
32 | */
|
---|
33 | virtual std::string encode(const bin & in) const
|
---|
34 | throw (cf::exception) = 0;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * decode(virtual)
|
---|
38 | * @return decoded binary
|
---|
39 | * @param in input
|
---|
40 | * @throw cf::exception
|
---|
41 | */
|
---|
42 | virtual bin decode(const std::string & in) const
|
---|
43 | throw (cf::exception) = 0;
|
---|
44 | };
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * base64 encoder/decoder
|
---|
48 | */
|
---|
49 | class base64 : public ICodec
|
---|
50 | {
|
---|
51 | public:
|
---|
52 | /**
|
---|
53 | * get instance
|
---|
54 | * @return base64 instance
|
---|
55 | */
|
---|
56 | static base64 * getInstance();
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * base64 encode
|
---|
60 | * @return base64 encoded string
|
---|
61 | * @param in input
|
---|
62 | * @throw cf::exception
|
---|
63 | */
|
---|
64 | std::string encode(const bin & in) const
|
---|
65 | throw (cf::exception);
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * base64 decode
|
---|
69 | * @return base64 decoded binary
|
---|
70 | * @param in base64 string
|
---|
71 | * @throw cf::exception
|
---|
72 | */
|
---|
73 | bin decode(const std::string & in) const
|
---|
74 | throw (cf::exception);
|
---|
75 | };
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * hex encoder/decoder
|
---|
79 | */
|
---|
80 | class hex : public ICodec
|
---|
81 | {
|
---|
82 | public:
|
---|
83 | /**
|
---|
84 | * get instance
|
---|
85 | * @return hex instance
|
---|
86 | */
|
---|
87 | static hex * getInstance();
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * hex encode
|
---|
91 | * @return hex encoded string
|
---|
92 | * @param in input
|
---|
93 | * @throw cf::exception
|
---|
94 | */
|
---|
95 | std::string encode(const bin & in) const
|
---|
96 | throw (cf::exception);
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * hex decode
|
---|
100 | * @return hex decoded binary
|
---|
101 | * @param in hex string
|
---|
102 | * @throw cf::exception
|
---|
103 | */
|
---|
104 | bin decode(const std::string & in) const
|
---|
105 | throw (cf::exception);
|
---|
106 | };
|
---|
107 | };
|
---|
108 | }
|
---|
109 |
|
---|
110 | #endif // #ifndef __cf_codec_h__
|
---|
Note:
See
TracBrowser
for help on using the repository browser.