IBR-DTNSuite  0.10
PlainSerializer.h
Go to the documentation of this file.
1 /*
2  * PlainSerializer.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 PLAINSERIALIZER_H_
23 #define PLAINSERIALIZER_H_
24 
25 #include <ibrdtn/data/Serializer.h>
26 #include <ibrdtn/data/Bundle.h>
28 #include <ibrdtn/data/Block.h>
29 
30 namespace dtn
31 {
32  namespace api
33  {
35  {
36  public:
37  enum Encoding {
42  };
43 
44  static Encoding parseEncoding(const std::string &data);
45  static std::string printEncoding(const Encoding &enc);
46 
47  PlainSerializer(std::ostream &stream, Encoding enc = BASE64);
48  virtual ~PlainSerializer();
49 
53 
54  void writeData(const dtn::data::Block &block);
55  void writeData(std::istream &stream, const dtn::data::Length &len);
56 
60 
61  private:
62  std::ostream &_stream;
63  Encoding _encoding;
64  };
65 
67  {
68  public:
71 
72  PlainDeserializer(std::istream &stream);
73  virtual ~PlainDeserializer();
74 
79 
86 
90  void readData(std::ostream &stream);
91 
92  private:
93  std::istream &_stream;
94  bool _lastblock;
95 
96  public:
98  {
99  public:
101  {
102  }
103  };
104 
106  {
107  public:
108  UnknownBlockException(string what = "unknown block") throw() : PlainDeserializerException(what)
109  {
110  }
111  };
112 
114  {
115  public:
116  BlockNotProcessableException(string what = "block not processable") throw() : PlainDeserializerException(what)
117  {
118  }
119  };
120 
121  };
122  }
123 }
124 
125 #endif /* PLAINSERIALIZER_H_ */