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
38fa6481
Commit
38fa6481
authored
Aug 16, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate missed review feedback
parent
aa1dee57
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
25 deletions
+68
-25
libcaf_core/caf/binary_deserializer.hpp
libcaf_core/caf/binary_deserializer.hpp
+19
-20
libcaf_core/caf/detail/type_traits.hpp
libcaf_core/caf/detail/type_traits.hpp
+3
-0
libcaf_core/caf/serializer_impl.hpp
libcaf_core/caf/serializer_impl.hpp
+5
-0
libcaf_core/caf/span.hpp
libcaf_core/caf/span.hpp
+1
-1
libcaf_core/src/binary_deserializer.cpp
libcaf_core/src/binary_deserializer.cpp
+38
-4
libcaf_core/test/serializer_impl.cpp
libcaf_core/test/serializer_impl.cpp
+2
-0
No files found.
libcaf_core/caf/binary_deserializer.hpp
View file @
38fa6481
...
@@ -37,28 +37,26 @@ public:
...
@@ -37,28 +37,26 @@ public:
// -- constructors, destructors, and assignment operators --------------------
// -- constructors, destructors, and assignment operators --------------------
binary_deserializer
(
actor_system
&
sys
,
span
<
const
byte
>
bytes
)
binary_deserializer
(
actor_system
&
sys
,
span
<
const
byte
>
bytes
);
:
super
(
sys
),
current_
(
bytes
.
begin
()),
end_
(
bytes
.
end
())
{
// nop
}
binary_deserializer
(
execution_unit
*
ctx
,
span
<
const
byte
>
bytes
)
binary_deserializer
(
execution_unit
*
ctx
,
span
<
const
byte
>
bytes
);
:
super
(
ctx
),
current_
(
bytes
.
begin
()),
end_
(
bytes
.
end
())
{
// nop
}
template
<
class
T
>
template
<
class
T
>
binary_deserializer
(
actor_system
&
sys
,
const
std
::
vector
<
T
>&
buf
)
binary_deserializer
(
actor_system
&
sys
,
const
std
::
vector
<
T
>&
buf
)
:
binary_deserializer
(
sys
,
as_bytes
(
make_span
(
buf
.
data
(),
buf
.
size
()
)))
{
:
binary_deserializer
(
sys
,
as_bytes
(
make_span
(
buf
)))
{
// nop
// nop
}
}
template
<
class
T
>
template
<
class
T
>
binary_deserializer
(
execution_unit
*
ctx
,
const
std
::
vector
<
T
>&
buf
)
binary_deserializer
(
execution_unit
*
ctx
,
const
std
::
vector
<
T
>&
buf
)
:
binary_deserializer
(
ctx
,
as_bytes
(
make_span
(
buf
.
data
(),
buf
.
size
()
)))
{
:
binary_deserializer
(
ctx
,
as_bytes
(
make_span
(
buf
)))
{
// nop
// nop
}
}
binary_deserializer
(
actor_system
&
sys
,
const
char
*
buf
,
size_t
buf_size
);
binary_deserializer
(
execution_unit
*
ctx
,
const
char
*
buf
,
size_t
buf_size
);
// -- overridden member functions --------------------------------------------
// -- overridden member functions --------------------------------------------
error
begin_object
(
uint16_t
&
typenr
,
std
::
string
&
name
)
override
;
error
begin_object
(
uint16_t
&
typenr
,
std
::
string
&
name
)
override
;
...
@@ -74,23 +72,24 @@ public:
...
@@ -74,23 +72,24 @@ public:
// -- properties -------------------------------------------------------------
// -- properties -------------------------------------------------------------
/// Returns the current read position.
/// Returns the current read position.
const
byte
*
current
()
const
{
const
char
*
current
()
const
CAF_DEPRECATED_MSG
(
"use remaining() instead"
);
return
current_
;
}
/// Returns the past-the-end iterator.
/// Returns the past-the-end iterator.
const
byte
*
end
()
const
{
const
char
*
end
()
const
CAF_DEPRECATED_MSG
(
"use remaining() instead"
);
return
end_
;
}
/// Returns how many bytes are still available to read.
/// Returns how many bytes are still available to read.
size_t
remaining
()
const
;
size_t
remaining
()
const
noexcept
{
return
static_cast
<
size_t
>
(
end_
-
current_
);
}
/// Returns the remaining bytes.
span
<
const
byte
>
remainder
()
const
noexcept
{
return
make_span
(
current_
,
end_
);
}
/// Jumps `num_bytes` forward.
/// Jumps `num_bytes` forward.
/// @pre `num_bytes <= remaining()`
/// @pre `num_bytes <= remaining()`
void
skip
(
size_t
num_bytes
)
{
void
skip
(
size_t
num_bytes
);
current_
+=
num_bytes
;
}
protected:
protected:
error
apply_impl
(
int8_t
&
)
override
;
error
apply_impl
(
int8_t
&
)
override
;
...
...
libcaf_core/caf/detail/type_traits.hpp
View file @
38fa6481
...
@@ -57,6 +57,9 @@ using enable_if_t = typename std::enable_if<V, T>::type;
...
@@ -57,6 +57,9 @@ using enable_if_t = typename std::enable_if<V, T>::type;
template
<
class
Trait
,
class
T
=
void
>
template
<
class
Trait
,
class
T
=
void
>
using
enable_if_tt
=
typename
std
::
enable_if
<
Trait
::
value
,
T
>::
type
;
using
enable_if_tt
=
typename
std
::
enable_if
<
Trait
::
value
,
T
>::
type
;
template
<
class
T
>
using
remove_reference_t
=
typename
std
::
remove_reference
<
T
>::
type
;
/// Checks whether `T` is inspectable by `Inspector`.
/// Checks whether `T` is inspectable by `Inspector`.
template
<
class
Inspector
,
class
T
>
template
<
class
Inspector
,
class
T
>
class
is_inspectable
{
class
is_inspectable
{
...
...
libcaf_core/caf/serializer_impl.hpp
View file @
38fa6481
...
@@ -43,6 +43,11 @@ public:
...
@@ -43,6 +43,11 @@ public:
using
value_type
=
typename
container_type
::
value_type
;
using
value_type
=
typename
container_type
::
value_type
;
// -- invariants -------------------------------------------------------------
static_assert
(
sizeof
(
value_type
)
==
1
,
"container must have a byte-sized value type"
);
// -- constructors, destructors, and assignment operators --------------------
// -- constructors, destructors, and assignment operators --------------------
serializer_impl
(
actor_system
&
sys
,
container_type
&
buf
)
serializer_impl
(
actor_system
&
sys
,
container_type
&
buf
)
...
...
libcaf_core/caf/span.hpp
View file @
38fa6481
...
@@ -211,7 +211,7 @@ span<byte> as_writable_bytes(span<T> xs) {
...
@@ -211,7 +211,7 @@ span<byte> as_writable_bytes(span<T> xs) {
/// Convenience function to make using `caf::span` more convenient without the
/// Convenience function to make using `caf::span` more convenient without the
/// deduction guides.
/// deduction guides.
template
<
class
T
>
template
<
class
T
>
auto
make_span
(
T
&
xs
)
->
span
<
detail
::
decay
_t
<
decltype
(
xs
[
0
])
>>
{
auto
make_span
(
T
&
xs
)
->
span
<
detail
::
remove_reference
_t
<
decltype
(
xs
[
0
])
>>
{
return
{
xs
.
data
(),
xs
.
size
()};
return
{
xs
.
data
(),
xs
.
size
()};
}
}
...
...
libcaf_core/src/binary_deserializer.cpp
View file @
38fa6481
...
@@ -50,6 +50,32 @@ error apply_float(binary_deserializer& bs, T& x) {
...
@@ -50,6 +50,32 @@ error apply_float(binary_deserializer& bs, T& x) {
}
// namespace
}
// namespace
binary_deserializer
::
binary_deserializer
(
actor_system
&
sys
,
span
<
const
byte
>
bytes
)
:
super
(
sys
),
current_
(
bytes
.
data
()),
end_
(
bytes
.
data
()
+
bytes
.
size
())
{
// nop
}
binary_deserializer
::
binary_deserializer
(
execution_unit
*
ctx
,
span
<
const
byte
>
bytes
)
:
super
(
ctx
),
current_
(
bytes
.
data
()),
end_
(
bytes
.
data
()
+
bytes
.
size
())
{
// nop
}
binary_deserializer
::
binary_deserializer
(
actor_system
&
sys
,
const
char
*
buf
,
size_t
buf_size
)
:
binary_deserializer
(
sys
,
make_span
(
reinterpret_cast
<
const
byte
*>
(
buf
),
buf_size
))
{
// nop
}
binary_deserializer
::
binary_deserializer
(
execution_unit
*
ctx
,
const
char
*
buf
,
size_t
buf_size
)
:
binary_deserializer
(
ctx
,
make_span
(
reinterpret_cast
<
const
byte
*>
(
buf
),
buf_size
))
{
// nop
}
error
binary_deserializer
::
begin_object
(
uint16_t
&
nr
,
std
::
string
&
name
)
{
error
binary_deserializer
::
begin_object
(
uint16_t
&
nr
,
std
::
string
&
name
)
{
if
(
auto
err
=
apply
(
nr
))
if
(
auto
err
=
apply
(
nr
))
return
err
;
return
err
;
...
@@ -89,8 +115,17 @@ error binary_deserializer::apply_raw(size_t num_bytes, void* storage) {
...
@@ -89,8 +115,17 @@ error binary_deserializer::apply_raw(size_t num_bytes, void* storage) {
return
none
;
return
none
;
}
}
size_t
binary_deserializer
::
remaining
()
const
{
const
char
*
binary_deserializer
::
current
()
const
{
return
static_cast
<
size_t
>
(
end_
-
current_
);
return
reinterpret_cast
<
const
char
*>
(
current_
);
}
const
char
*
binary_deserializer
::
end
()
const
{
return
reinterpret_cast
<
const
char
*>
(
end_
);
}
void
binary_deserializer
::
skip
(
size_t
num_bytes
)
{
CAF_ASSERT
(
num_bytes
<=
remaining
());
current_
+=
num_bytes
;
}
}
error
binary_deserializer
::
apply_impl
(
int8_t
&
x
)
{
error
binary_deserializer
::
apply_impl
(
int8_t
&
x
)
{
...
@@ -149,8 +184,7 @@ error binary_deserializer::apply_impl(std::string& x) {
...
@@ -149,8 +184,7 @@ error binary_deserializer::apply_impl(std::string& x) {
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
(
reinterpret_cast
<
const
char
*>
(
current_
),
x
.
assign
(
reinterpret_cast
<
const
char
*>
(
current_
),
str_size
);
reinterpret_cast
<
const
char
*>
(
current_
)
+
str_size
);
current_
+=
str_size
;
current_
+=
str_size
;
return
end_sequence
();
return
end_sequence
();
}
}
...
...
libcaf_core/test/serializer_impl.cpp
View file @
38fa6481
...
@@ -53,6 +53,7 @@ struct test_data {
...
@@ -53,6 +53,7 @@ struct test_data {
ts_
(
ts
),
ts_
(
ts
),
te_
(
te
),
te_
(
te
),
str_
(
str
)
{
str_
(
str
)
{
// nop
}
}
test_data
()
test_data
()
...
@@ -61,6 +62,7 @@ struct test_data {
...
@@ -61,6 +62,7 @@ struct test_data {
caf
::
timestamp
{
caf
::
timestamp
{
caf
::
timestamp
::
duration
{
1478715821
*
1000000000ll
}},
caf
::
timestamp
::
duration
{
1478715821
*
1000000000ll
}},
test_enum
::
b
,
"Lorem ipsum dolor sit amet."
)
{
test_enum
::
b
,
"Lorem ipsum dolor sit amet."
)
{
// nop
}
}
int32_t
i32_
;
int32_t
i32_
;
...
...
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