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
8ef32d55
Commit
8ef32d55
authored
Sep 26, 2015
by
ufownl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the issue of empty non-POD classes serialization
parent
602dda7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
4 deletions
+59
-4
libcaf_core/caf/detail/default_uniform_type_info.hpp
libcaf_core/caf/detail/default_uniform_type_info.hpp
+42
-4
libcaf_core/test/serialization.cpp
libcaf_core/test/serialization.cpp
+17
-0
No files found.
libcaf_core/caf/detail/default_uniform_type_info.hpp
View file @
8ef32d55
...
@@ -266,7 +266,8 @@ private:
...
@@ -266,7 +266,8 @@ private:
template
<
class
T
,
class
AccessPolicy
,
template
<
class
T
,
class
AccessPolicy
,
class
SerializePolicy
=
default_serialize_policy
,
class
SerializePolicy
=
default_serialize_policy
,
bool
IsEnum
=
std
::
is_enum
<
T
>
::
value
,
bool
IsEnum
=
std
::
is_enum
<
T
>
::
value
,
bool
IsEmptyType
=
std
::
is_class
<
T
>::
value
&&
std
::
is_empty
<
T
>::
value
>
bool
IsEmptyType
=
std
::
is_class
<
T
>::
value
&&
std
::
is_empty
<
T
>::
value
>
class
member_tinfo
:
public
abstract_uniform_type_info
<
T
>
{
class
member_tinfo
:
public
abstract_uniform_type_info
<
T
>
{
public:
public:
using
super
=
abstract_uniform_type_info
<
T
>
;
using
super
=
abstract_uniform_type_info
<
T
>
;
...
@@ -296,7 +297,6 @@ public:
...
@@ -296,7 +297,6 @@ public:
}
}
private:
private:
void
ds
(
void
*
p
,
deserializer
*
d
,
std
::
true_type
)
const
{
void
ds
(
void
*
p
,
deserializer
*
d
,
std
::
true_type
)
const
{
spol_
(
apol_
(
p
),
d
);
spol_
(
apol_
(
p
),
d
);
}
}
...
@@ -309,7 +309,6 @@ private:
...
@@ -309,7 +309,6 @@ private:
AccessPolicy
apol_
;
AccessPolicy
apol_
;
SerializePolicy
spol_
;
SerializePolicy
spol_
;
};
};
template
<
class
T
,
class
A
,
class
S
>
template
<
class
T
,
class
A
,
class
S
>
...
@@ -339,6 +338,38 @@ public:
...
@@ -339,6 +338,38 @@ public:
}
}
};
};
template
<
class
T
>
struct
empty_non_pod_type_wrapper
{
// nop
};
template
<
class
T
,
class
A
,
class
S
>
class
member_tinfo
<
empty_non_pod_type_wrapper
<
T
>
,
A
,
S
,
false
,
true
>
:
public
abstract_uniform_type_info
<
T
>
{
public:
using
super
=
abstract_uniform_type_info
<
T
>
;
member_tinfo
(
const
A
&
,
const
S
&
)
:
super
(
"--member--"
)
{
// nop
}
member_tinfo
(
const
A
&
)
:
super
(
"--member--"
)
{
// nop
}
member_tinfo
()
:
super
(
"--member--"
)
{
// nop
}
void
serialize
(
const
void
*
,
serializer
*
)
const
override
{
// nop
}
void
deserialize
(
void
*
,
deserializer
*
)
const
override
{
// nop
}
};
template
<
class
T
,
class
AccessPolicy
,
class
SerializePolicy
>
template
<
class
T
,
class
AccessPolicy
,
class
SerializePolicy
>
class
member_tinfo
<
T
,
AccessPolicy
,
SerializePolicy
,
true
,
false
>
class
member_tinfo
<
T
,
AccessPolicy
,
SerializePolicy
,
true
,
false
>
:
public
abstract_uniform_type_info
<
T
>
{
:
public
abstract_uniform_type_info
<
T
>
{
...
@@ -503,7 +534,14 @@ public:
...
@@ -503,7 +534,14 @@ public:
}
}
default_uniform_type_info
(
std
::
string
tname
)
:
super
(
std
::
move
(
tname
))
{
default_uniform_type_info
(
std
::
string
tname
)
:
super
(
std
::
move
(
tname
))
{
using
result_type
=
member_tinfo
<
T
,
fake_access_policy
<
T
>>
;
using
result_type
=
member_tinfo
<
typename
std
::
conditional
<
std
::
is_polymorphic
<
T
>::
value
,
empty_non_pod_type_wrapper
<
T
>
,
T
>::
type
,
fake_access_policy
<
T
>
>
;
members_
.
push_back
(
uniform_type_info_ptr
(
new
result_type
));
members_
.
push_back
(
uniform_type_info_ptr
(
new
result_type
));
}
}
...
...
libcaf_core/test/serialization.cpp
View file @
8ef32d55
...
@@ -111,6 +111,15 @@ struct test_array {
...
@@ -111,6 +111,15 @@ struct test_array {
int
value2
[
2
][
4
];
int
value2
[
2
][
4
];
};
};
struct
test_empty_non_pod
{
virtual
void
foo
()
{
// nop
}
bool
operator
==
(
const
test_empty_non_pod
&
)
const
{
return
false
;
}
};
struct
fixture
{
struct
fixture
{
int32_t
i32
=
-
345
;
int32_t
i32
=
-
345
;
test_enum
te
=
test_enum
::
b
;
test_enum
te
=
test_enum
::
b
;
...
@@ -129,6 +138,7 @@ struct fixture {
...
@@ -129,6 +138,7 @@ struct fixture {
announce
<
test_enum
>
(
"test_enum"
);
announce
<
test_enum
>
(
"test_enum"
);
announce
(
typeid
(
raw_struct
),
uniform_type_info_ptr
{
new
raw_struct_type_info
});
announce
(
typeid
(
raw_struct
),
uniform_type_info_ptr
{
new
raw_struct_type_info
});
announce
<
test_array
>
(
"test_array"
,
&
test_array
::
value
,
&
test_array
::
value2
);
announce
<
test_array
>
(
"test_array"
,
&
test_array
::
value
,
&
test_array
::
value2
);
announce
<
test_empty_non_pod
>
(
"test_empty_non_pod"
);
rs
.
str
.
assign
(
string
(
str
.
rbegin
(),
str
.
rend
()));
rs
.
str
.
assign
(
string
(
str
.
rbegin
(),
str
.
rend
()));
msg
=
make_message
(
i32
,
te
,
str
,
rs
);
msg
=
make_message
(
i32
,
te
,
str
,
rs
);
}
}
...
@@ -286,6 +296,13 @@ CAF_TEST(test_array_serialization) {
...
@@ -286,6 +296,13 @@ CAF_TEST(test_array_serialization) {
}
}
}
}
CAF_TEST
(
test_empty_non_pod_serialization
)
{
test_empty_non_pod
x
;
auto
buf
=
binary_util
::
serialize
(
x
);
binary_util
::
deserialize
(
buf
,
&
x
);
CAF_CHECK
(
true
);
}
CAF_TEST
(
test_single_message
)
{
CAF_TEST
(
test_single_message
)
{
auto
buf
=
binary_util
::
serialize
(
msg
);
auto
buf
=
binary_util
::
serialize
(
msg
);
message
x
;
message
x
;
...
...
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