tobicore
7.0.0
Main Page
Modules
Classes
Files
Examples
File List
All
Classes
Functions
Variables
Typedefs
Enumerator
Friends
Groups
Pages
IDSerializer.cpp
1
/*
2
Copyright (C) 2009-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
3
Michele Tavella <michele.tavella@epfl.ch>
4
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include "IDSerializer.hpp"
20
#include <string.h>
21
22
#ifdef __BORLANDC__
23
using namespace
std;
24
#endif
25
26
IDSerializer::IDSerializer
(
void
) {
27
this->
message
= NULL;
28
}
29
30
IDSerializer::IDSerializer
(
IDMessage
*
const
message
) {
31
this->message =
message
;
32
}
33
34
IDSerializer::~IDSerializer
(
void
) {
35
this->
message
= NULL;
36
}
37
38
IDSerializer
*
IDSerializer::SetMessage
(
IDMessage
*
const
message
) {
39
this->message =
message
;
40
return
this
;
41
}
42
43
std::string
IDSerializer::SerializeCp
(
void
) {
44
std::string cache;
45
this->
Serialize
(&cache);
46
return
cache;
47
}
48
49
void
IDSerializer::DeserializeCp
(
const
std::string& buffer) {
50
std::string cache(buffer);
51
this->
Deserialize
(&cache);
52
}
53
54
char
*
IDSerializer::SerializeCh
(
char
*
const
buffer,
const
unsigned
int
bsize) {
55
if
(this->
message
== NULL)
56
return
NULL;
57
58
std::string cache;
59
this->
Serialize
(&cache);
60
if
(bsize <= cache.size())
61
return
NULL;
62
63
memset(buffer, 0, bsize *
sizeof
(
char
));
64
strcpy(buffer, cache.c_str());
65
return
buffer;
66
}
67
68
const
char
*
IDSerializer::DeserializeCh
(
const
char
* buffer,
unsigned
int
bsize) {
69
if
(this->
message
== NULL)
70
return
NULL;
71
72
std::string cache(buffer);
73
this->
Deserialize
(&cache);
74
return
buffer;
75
}
tobiid
IDSerializer.cpp
Generated on Tue Oct 23 2012 13:15:34 for tobicore by
1.8.1.2