Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
1c77c35d
Commit
1c77c35d
authored
Aug 10, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish deserializer_impl and add some tests
parent
b375feab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
177 additions
and
7 deletions
+177
-7
libcaf_core/caf/deserializer_impl.hpp
libcaf_core/caf/deserializer_impl.hpp
+9
-7
libcaf_core/test/deserializer_impl.cpp
libcaf_core/test/deserializer_impl.cpp
+81
-0
libcaf_core/test/serialization_fixture.hpp
libcaf_core/test/serialization_fixture.hpp
+87
-0
No files found.
libcaf_core/caf/deserializer_impl.hpp
View file @
1c77c35d
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
#pragma once
#pragma once
#include <caf/detail/ieee_754.hpp>
#include <caf/detail/network_order.hpp>
#include <cstddef>
#include <cstddef>
#include <cstdint>
#include <cstdint>
#include <vector>
#include <vector>
...
@@ -40,23 +42,23 @@ public:
...
@@ -40,23 +42,23 @@ public:
// -- constructors, destructors, and assignment operators --------------------
// -- constructors, destructors, and assignment operators --------------------
serializer_impl
(
actor_system
&
sys
,
const
value_type
*
buf
,
size_t
buf_size
)
de
serializer_impl
(
actor_system
&
sys
,
const
value_type
*
buf
,
size_t
buf_size
)
:
super
(
sys
),
current_
(
buf
),
end_
(
buf
+
buf_size
)
{
:
super
(
sys
),
current_
(
buf
),
end_
(
buf
+
buf_size
)
{
// nop
// nop
}
}
serializer_impl
(
execution_unit
*
ctx
,
const
value_type
*
buf
,
size_t
buf_size
)
de
serializer_impl
(
execution_unit
*
ctx
,
const
value_type
*
buf
,
size_t
buf_size
)
:
super
(
ctx
),
current_
(
buf
),
end_
(
buf
+
buf_size
)
{
:
super
(
ctx
),
current_
(
buf
),
end_
(
buf
+
buf_size
)
{
// nop
// nop
}
}
serializer_impl
(
actor_system
&
sys
,
const
container_type
&
buf
)
de
serializer_impl
(
actor_system
&
sys
,
const
container_type
&
buf
)
:
serializer_impl
(
sys
,
buf
.
data
(),
buf
.
size
())
{
:
de
serializer_impl
(
sys
,
buf
.
data
(),
buf
.
size
())
{
// nop
// nop
}
}
serializer_impl
(
execution_unit
*
ctx
,
const
container_type
&
buf
)
de
serializer_impl
(
execution_unit
*
ctx
,
const
container_type
&
buf
)
:
serializer_impl
(
ctx
,
buf
.
data
(),
buf
.
size
())
{
:
de
serializer_impl
(
ctx
,
buf
.
data
(),
buf
.
size
())
{
// nop
// nop
}
}
// -- overridden member functions --------------------------------------------
// -- overridden member functions --------------------------------------------
...
@@ -179,7 +181,7 @@ protected:
...
@@ -179,7 +181,7 @@ protected:
return
err
;
return
err
;
if
(
!
range_check
(
str_size
))
if
(
!
range_check
(
str_size
))
return
sec
::
end_of_stream
;
return
sec
::
end_of_stream
;
x
.
assign
(
current_
,
current_
+
str_size
);
x
.
assign
(
(
char
*
)
current_
,
(
char
*
)
current_
+
str_size
);
current_
+=
str_size
;
current_
+=
str_size
;
return
end_sequence
();
return
end_sequence
();
}
}
...
...
libcaf_core/test/deserializer_impl.cpp
0 → 100644
View file @
1c77c35d
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/config.hpp"
#define CAF_SUITE deserializer_impl
#include "caf/test/unit_test.hpp"
#include <vector>
#include "serialization_fixture.hpp"
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/serializer_impl.hpp"
#include "caf/deserializer_impl.hpp"
#include "caf/byte.hpp"
using
namespace
caf
;
CAF_TEST_FIXTURE_SCOPE
(
deserialization_tests
,
serialization_fixture
)
CAF_TEST
(
"deserialize std::vector<char>"
)
{
using
container_type
=
std
::
vector
<
char
>
;
container_type
buffer
;
serializer_impl
<
container_type
>
serializer
{
sys
,
buffer
};
if
(
auto
err
=
serializer
(
source
))
CAF_FAIL
(
"serialisation with serializer_impl<std::vector<char>> failed: "
<<
sys
.
render
(
err
));
deserializer_impl
<
container_type
>
deserializer
{
sys
,
buffer
};
if
(
auto
err
=
deserializer
(
sink
))
CAF_FAIL
(
"deserialisation with deserializer_impl<std::vector<char>> failed:"
<<
sys
.
render
(
err
));
CAF_CHECK_EQUAL
(
source
,
sink
);
}
CAF_TEST
(
"deserialize std::vector<byte>"
)
{
using
container_type
=
std
::
vector
<
byte
>
;
container_type
buffer
;
serializer_impl
<
container_type
>
serializer
{
sys
,
buffer
};
if
(
auto
err
=
serializer
(
source
))
CAF_FAIL
(
"serialisation with serializer_impl<std::vector<byte>> failed: "
<<
sys
.
render
(
err
));
deserializer_impl
<
container_type
>
deserializer
{
sys
,
buffer
};
if
(
auto
err
=
deserializer
(
sink
))
CAF_FAIL
(
"deserialisation with deserializer_impl<std::vector<byte>> failed:"
<<
sys
.
render
(
err
));
CAF_CHECK_EQUAL
(
source
,
sink
);
}
CAF_TEST
(
"deserialize std::vector<uint8_t>"
)
{
using
container_type
=
std
::
vector
<
uint8_t
>
;
container_type
buffer
;
serializer_impl
<
container_type
>
serializer
{
sys
,
buffer
};
if
(
auto
err
=
serializer
(
source
))
CAF_FAIL
(
"serialisation with serializer_impl<std::vector<uint8_t>> failed: "
<<
sys
.
render
(
err
));
deserializer_impl
<
container_type
>
deserializer
{
sys
,
buffer
};
if
(
auto
err
=
deserializer
(
sink
))
CAF_FAIL
(
"deserialisation with deserializer_impl<std::vector<uint8_t>> failed:"
<<
sys
.
render
(
err
));
CAF_CHECK_EQUAL
(
source
,
sink
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/serialization_fixture.hpp
0 → 100644
View file @
1c77c35d
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/timestamp.hpp"
#include "caf/duration.hpp"
enum
class
test_enum
{
a
,
b
,
c
,
};
struct
test_data
{
test_data
(
int32_t
i32
,
int64_t
i64
,
float
f32
,
double
f64
,
caf
::
duration
dur
,
caf
::
timestamp
ts
,
test_enum
te
,
const
std
::
string
&
str
)
:
i32_
(
i32
),
i64_
(
i64
),
f32_
(
f32
),
f64_
(
f64
),
dur_
(
dur
),
ts_
(
ts
),
te_
(
te
),
str_
(
str
)
{
}
test_data
()
:
test_data
(
-
345
,
-
1234567890123456789ll
,
3.45
,
54.3
,
caf
::
duration
(
caf
::
time_unit
::
seconds
,
123
),
caf
::
timestamp
{
caf
::
timestamp
::
duration
{
1478715821
*
1000000000ll
}},
test_enum
::
b
,
"Lorem ipsum dolor sit amet."
)
{
}
int32_t
i32_
;
int64_t
i64_
;
float
f32_
;
double
f64_
;
caf
::
duration
dur_
;
caf
::
timestamp
ts_
;
test_enum
te_
;
std
::
string
str_
;
friend
bool
operator
==
(
const
test_data
&
data
,
const
test_data
&
other
)
{
return
(
data
.
f64_
==
other
.
f64_
&&
data
.
i32_
==
other
.
i32_
&&
data
.
i64_
==
other
.
i64_
&&
data
.
str_
==
other
.
str_
&&
data
.
te_
==
other
.
te_
&&
data
.
ts_
==
other
.
ts_
);
}
};
template
<
class
Inspector
>
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
test_data
&
x
)
{
return
f
(
caf
::
meta
::
type_name
(
"test_data"
),
x
.
i32_
,
x
.
i64_
,
x
.
f32_
,
x
.
f64_
,
x
.
dur_
,
x
.
ts_
,
x
.
te_
,
x
.
str_
);
}
struct
serialization_fixture
{
caf
::
actor_system_config
cfg
;
caf
::
actor_system
sys
{
cfg
};
test_data
source
;
test_data
sink
{
0
,
0
,
0
,
0
,
caf
::
duration
(
caf
::
time_unit
::
seconds
,
0
),
caf
::
timestamp
{
caf
::
timestamp
::
duration
{
0
}},
test_enum
::
a
,
""
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment