IBR-DTNSuite
0.10
Main Page
Namespaces
Classes
Files
File List
File Members
Serializer.h
Go to the documentation of this file.
1
/*
2
* Serializer.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 _SERIALIZER_H
23
#define _SERIALIZER_H
24
25
#include <iostream>
26
#include "
ibrdtn/data/Dictionary.h
"
27
#include "
ibrdtn/data/PrimaryBlock.h
"
28
#include "
ibrdtn/data/Exceptions.h
"
29
#include "
ibrdtn/data/BundleFragment.h
"
30
31
namespace
dtn
32
{
33
namespace
data
34
{
35
class
Bundle;
36
class
Block;
37
class
PrimaryBlock;
38
class
PayloadBlock;
39
class
MetaBundle;
40
41
class
Serializer
42
{
43
public
:
44
virtual
~Serializer
() {};
45
46
virtual
Serializer
&
operator<<
(
const
dtn::data::Bundle
&obj) = 0;
47
virtual
Serializer
&
operator<<
(
const
dtn::data::PrimaryBlock
&obj) = 0;
48
virtual
Serializer
&
operator<<
(
const
dtn::data::Block
&obj) = 0;
49
virtual
Serializer
&
operator<<
(
const
dtn::data::BundleFragment
&obj)
50
{
51
(*this) << obj.
_bundle
;
52
return
(*
this
);
53
};
54
55
virtual
Length
getLength
(
const
dtn::data::Bundle
&obj) = 0;
56
virtual
Length
getLength
(
const
dtn::data::PrimaryBlock
&obj)
const
= 0;
57
virtual
Length
getLength
(
const
dtn::data::Block
&obj)
const
= 0;
58
};
59
60
class
Deserializer
61
{
62
public
:
63
virtual
~Deserializer
() {};
64
65
virtual
Deserializer
&
operator>>
(
dtn::data::Bundle
&obj) = 0;
66
virtual
Deserializer
&
operator>>
(
dtn::data::PrimaryBlock
&obj) = 0;
67
virtual
Deserializer
&
operator>>
(
dtn::data::Block
&obj) = 0;
68
};
69
70
class
Validator
71
{
72
public
:
73
class
RejectedException
:
public
dtn::SerializationFailedException
74
{
75
public
:
76
RejectedException
(
string
what
=
"A validate method has the bundle rejected."
) throw() : dtn::
SerializationFailedException
(
what
)
77
{
78
};
79
};
80
81
virtual
~Validator
() {};
82
83
virtual
void
validate
(
const
dtn::data::PrimaryBlock
&)
const
throw (RejectedException) = 0;
84
virtual
void
validate
(const dtn::data::
Block
&, const dtn::data::
Number
&) const throw (RejectedException) = 0;
85
virtual
void
validate
(const dtn::data::
PrimaryBlock
&, const dtn::data::Block&, const dtn::data::
Number
&) const throw (RejectedException) = 0;
86
virtual
void
validate
(const dtn::data::
Bundle
&) const throw (RejectedException) = 0;
87
};
88
89
class
AcceptValidator
: public
Validator
90
{
91
public
:
92
AcceptValidator
();
93
virtual
~
AcceptValidator
();
94
95
virtual
void
validate
(
const
dtn::data::PrimaryBlock
&)
const
throw
(RejectedException);
96
virtual
void
validate
(
const
dtn::data::Block
&,
const
dtn::data::Number
&)
const
throw
(RejectedException);
97
virtual
void
validate
(
const
dtn::data::PrimaryBlock
&,
const
dtn::data::Block
&,
const
dtn::data::Number
&)
const
throw
(RejectedException);
98
virtual
void
validate
(
const
dtn::data::Bundle
&)
const
throw
(RejectedException);
99
};
100
101
class
DefaultSerializer
:
public
Serializer
102
{
103
public
:
108
DefaultSerializer
(std::ostream &stream);
109
116
DefaultSerializer
(std::ostream &stream,
const
Dictionary
&d);
117
121
virtual
~DefaultSerializer
() {};
122
123
virtual
Serializer
&
operator<<
(
const
dtn::data::Bundle
&obj);
124
virtual
Serializer
&
operator<<
(
const
dtn::data::PrimaryBlock
&obj);
125
virtual
Serializer
&
operator<<
(
const
dtn::data::Block
&obj);
126
virtual
Serializer
&
operator<<
(
const
dtn::data::BundleFragment
&obj);
127
128
virtual
Length
getLength(
const
dtn::data::Bundle
&obj);
129
virtual
Length
getLength(
const
dtn::data::PrimaryBlock
&obj)
const
;
130
virtual
Length
getLength(
const
dtn::data::Block
&obj)
const
;
131
132
protected
:
133
Serializer
&serialize(
const
dtn::data::PayloadBlock
& obj,
const
Length
&clip_offset,
const
Length
&clip_length);
134
void
rebuildDictionary(
const
dtn::data::Bundle
&obj);
135
bool
isCompressable(
const
dtn::data::Bundle
&obj)
const
;
136
std::ostream &
_stream
;
137
138
Dictionary
_dictionary
;
139
bool
_compressable
;
140
};
141
142
class
DefaultDeserializer
:
public
Deserializer
143
{
144
public
:
149
DefaultDeserializer
(std::istream &stream);
150
158
DefaultDeserializer
(std::istream &stream,
Validator
&v);
159
167
DefaultDeserializer
(std::istream &stream,
const
Dictionary
&d);
168
173
virtual
~DefaultDeserializer
() {};
174
175
virtual
Deserializer
&
operator>>
(
dtn::data::Bundle
&obj);
176
virtual
Deserializer
&
operator>>
(
dtn::data::PrimaryBlock
&obj);
177
virtual
Deserializer
&
operator>>
(
dtn::data::Block
&obj);
178
virtual
Deserializer
&read(
const
dtn::data::PrimaryBlock
&bundle,
dtn::data::Block
&obj);
179
virtual
Deserializer
&
operator>>
(
dtn::data::MetaBundle
&obj);
180
186
void
setFragmentationSupport(
bool
val);
187
188
protected
:
189
std::istream &
_stream
;
190
Validator
&
_validator
;
191
AcceptValidator
_default_validator
;
192
193
private
:
194
Dictionary
_dictionary;
195
bool
_compressed;
196
bool
_fragmentation;
197
};
198
199
class
SeparateSerializer
:
public
DefaultSerializer
200
{
201
public
:
202
SeparateSerializer
(std::ostream &stream);
203
virtual
~
SeparateSerializer
();
204
205
virtual
Serializer
&
operator<<
(
const
dtn::data::Block
&obj);
206
virtual
Length
getLength(
const
dtn::data::Block
&obj)
const
;
207
};
208
209
class
SeparateDeserializer
:
public
DefaultDeserializer
210
{
211
public
:
212
SeparateDeserializer
(std::istream &stream,
Bundle
&b);
213
virtual
~
SeparateDeserializer
();
214
215
dtn::data::Block
& readBlock();
216
217
private
:
218
Bundle
&_bundle;
219
};
220
}
221
}
222
223
224
#endif
/* _SERIALIZER_H */
225
ibrdtn
ibrdtn
data
Serializer.h
Generated on Mon Jul 22 2013 15:16:01 for IBR-DTNSuite by
1.8.3.1