IBR-DTNSuite  0.10
Base64Reader.h
Go to the documentation of this file.
1 /*
2  * Base64Reader.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef BASE64READER_H_
23 #define BASE64READER_H_
24 
25 #include "ibrcommon/data/Base64.h"
26 #include <iostream>
27 #include <vector>
28 #include <string.h>
29 #include <stdint.h>
30 
31 namespace ibrcommon
32 {
33  class Base64Reader : public std::basic_streambuf<char, std::char_traits<char> >, public std::istream
34  {
35  public:
36  Base64Reader(std::istream &stream, const size_t limit = 0, const size_t buffer = 2048);
37  virtual ~Base64Reader();
38 
39  protected:
40  virtual std::char_traits<char>::int_type underflow();
41 
42  private:
43  void set_b64(char val);
44 
45  std::istream &_stream;
46 
47  // Output buffer
48  std::vector<char> data_buf_;
49 
50  // length of the data buffer
51  size_t data_size_;
52 
53  uint8_t _base64_state;
54 
55  Base64::Group _group;
56  char _base64_padding;
57 
58  size_t _byte_read;
59  size_t _byte_limit;
60  };
61 }
62 
63 #endif /* BASE64READER_H_ */