IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
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
>
27
#include <
ibrdtn/data/PrimaryBlock.h
>
28
#include <
ibrdtn/data/Block.h
>
29
30
namespace
dtn
31
{
32
namespace
api
33
{
34
class
PlainSerializer
:
public
dtn::data::Serializer
35
{
36
public
:
37
enum
Encoding
{
38
INVALID
,
39
SKIP_PAYLOAD
,
40
BASE64
,
41
RAW
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
50
dtn::data::Serializer
&
operator<<
(
const
dtn::data::Bundle
&obj);
51
dtn::data::Serializer
&
operator<<
(
const
dtn::data::PrimaryBlock
&obj);
52
dtn::data::Serializer
&
operator<<
(
const
dtn::data::Block
&obj);
53
54
void
writeData
(
const
dtn::data::Block
&block);
55
void
writeData
(std::istream &stream,
const
dtn::data::Length
&len);
56
57
dtn::data::Length
getLength
(
const
dtn::data::Bundle
&obj);
58
dtn::data::Length
getLength
(
const
dtn::data::PrimaryBlock
&obj)
const
;
59
dtn::data::Length
getLength
(
const
dtn::data::Block
&obj)
const
;
60
61
private
:
62
std::ostream &_stream;
63
Encoding
_encoding;
64
};
65
66
class
PlainDeserializer
:
public
dtn::data::Deserializer
67
{
68
public
:
69
class
UnknownBlockException
;
70
class
BlockNotProcessableException
;
71
72
PlainDeserializer
(std::istream &stream);
73
virtual
~PlainDeserializer
();
74
75
dtn::data::Deserializer
&
operator>>
(
dtn::data::Bundle
&obj);
76
dtn::data::Deserializer
&
operator>>
(
dtn::data::PrimaryBlock
&obj);
77
dtn::data::Deserializer
&
operator>>
(
dtn::data::Block
&obj);
78
dtn::data::Deserializer
&
operator>>
(
ibrcommon::BLOB::iostream
&obj);
79
85
dtn::data::Block
&
readBlock
(
dtn::data::BundleBuilder
&builder);
86
90
void
readData
(std::ostream &stream);
91
92
private
:
93
std::istream &_stream;
94
bool
_lastblock;
95
96
public
:
97
class
PlainDeserializerException
:
public
ibrcommon::Exception
98
{
99
public
:
100
PlainDeserializerException
(
string
what
=
""
) throw() :
Exception
(
what
)
101
{
102
}
103
};
104
105
class
UnknownBlockException
:
public
PlainDeserializerException
106
{
107
public
:
108
UnknownBlockException
(
string
what
=
"unknown block"
) throw() :
PlainDeserializerException
(
what
)
109
{
110
}
111
};
112
113
class
BlockNotProcessableException
:
public
PlainDeserializerException
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_ */
ibrdtn
ibrdtn
api
PlainSerializer.h
Generated on Thu Mar 27 2014 09:26:21 for IBR-DTNSuite by
1.8.4