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
ea11a6e9
Commit
ea11a6e9
authored
Dec 21, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate review feedback
parent
82c456fe
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
28 deletions
+21
-28
libcaf_core/caf/binary_deserializer.hpp
libcaf_core/caf/binary_deserializer.hpp
+2
-2
libcaf_core/caf/config_value.hpp
libcaf_core/caf/config_value.hpp
+2
-2
libcaf_core/src/config_value.cpp
libcaf_core/src/config_value.cpp
+14
-22
libcaf_core/src/config_value_reader.cpp
libcaf_core/src/config_value_reader.cpp
+1
-0
libcaf_core/test/config_value.cpp
libcaf_core/test/config_value.cpp
+2
-2
No files found.
libcaf_core/caf/binary_deserializer.hpp
View file @
ea11a6e9
...
@@ -35,8 +35,8 @@
...
@@ -35,8 +35,8 @@
namespace
caf
{
namespace
caf
{
/// Deserializes
objects from sequence of bytes. Does not perform run-time typ
e
/// Deserializes
C++ objects from sequence of bytes. Does not perform run-tim
e
/// checks.
///
type
checks.
class
CAF_CORE_EXPORT
binary_deserializer
class
CAF_CORE_EXPORT
binary_deserializer
:
public
load_inspector_base
<
binary_deserializer
>
{
:
public
load_inspector_base
<
binary_deserializer
>
{
public:
public:
...
...
libcaf_core/caf/config_value.hpp
View file @
ea11a6e9
...
@@ -121,8 +121,8 @@ public:
...
@@ -121,8 +121,8 @@ public:
/// Tries to parse a value from `str`.
/// Tries to parse a value from `str`.
static
expected
<
config_value
>
parse
(
string_view
str
);
static
expected
<
config_value
>
parse
(
string_view
str
);
/// Tries to parse a config value (list) from `str` and t
hen converting it to
/// Tries to parse a config value (list) from `str` and t
o convert it to an
/// a
n a
llowed input message type for `Handle`.
/// allowed input message type for `Handle`.
template
<
class
Handle
>
template
<
class
Handle
>
static
optional
<
message
>
parse_msg
(
string_view
str
,
const
Handle
&
)
{
static
optional
<
message
>
parse_msg
(
string_view
str
,
const
Handle
&
)
{
auto
allowed
=
Handle
::
allowed_inputs
();
auto
allowed
=
Handle
::
allowed_inputs
();
...
...
libcaf_core/src/config_value.cpp
View file @
ea11a6e9
...
@@ -308,12 +308,7 @@ expected<timespan> config_value::to_timespan() const {
...
@@ -308,12 +308,7 @@ expected<timespan> config_value::to_timespan() const {
auto
f
=
detail
::
make_overload
(
auto
f
=
detail
::
make_overload
(
no_conversions
<
timespan
,
none_t
,
bool
,
integer
,
real
,
uri
,
no_conversions
<
timespan
,
none_t
,
bool
,
integer
,
real
,
uri
,
config_value
::
list
,
config_value
::
dictionary
>
(),
config_value
::
list
,
config_value
::
dictionary
>
(),
[](
timespan
x
)
{
[](
timespan
x
)
{
return
result_type
{
x
};
},
// This cast may lose precision on the value. We could try and check that,
// but refusing to convert on loss of precision could also be unexpected
// behavior. So we rather always convert, even if it costs precision.
return
result_type
{
x
};
},
[](
const
std
::
string
&
x
)
{
[](
const
std
::
string
&
x
)
{
auto
tmp
=
timespan
{};
auto
tmp
=
timespan
{};
if
(
detail
::
parse
(
x
,
tmp
)
==
none
)
if
(
detail
::
parse
(
x
,
tmp
)
==
none
)
...
@@ -328,9 +323,18 @@ expected<timespan> config_value::to_timespan() const {
...
@@ -328,9 +323,18 @@ expected<timespan> config_value::to_timespan() const {
expected
<
config_value
::
list
>
config_value
::
to_list
()
const
{
expected
<
config_value
::
list
>
config_value
::
to_list
()
const
{
using
result_type
=
expected
<
list
>
;
using
result_type
=
expected
<
list
>
;
auto
dict_to_list
=
[](
const
dictionary
&
dict
,
list
&
result
)
{
for
(
const
auto
&
[
key
,
val
]
:
dict
)
{
list
kvp
;
kvp
.
reserve
(
2
);
kvp
.
emplace_back
(
key
);
kvp
.
emplace_back
(
val
);
result
.
emplace_back
(
std
::
move
(
kvp
));
}
};
auto
f
=
detail
::
make_overload
(
auto
f
=
detail
::
make_overload
(
no_conversions
<
list
,
none_t
,
bool
,
integer
,
real
,
timespan
,
uri
>
(),
no_conversions
<
list
,
none_t
,
bool
,
integer
,
real
,
timespan
,
uri
>
(),
[](
const
std
::
string
&
x
)
{
[
dict_to_list
](
const
std
::
string
&
x
)
{
// Check whether we can parse the string as a list. If that fails, try
// Check whether we can parse the string as a list. If that fails, try
// whether we can parse it as a dictionary instead (and then convert that
// whether we can parse it as a dictionary instead (and then convert that
// to a list).
// to a list).
...
@@ -340,13 +344,7 @@ expected<config_value::list> config_value::to_list() const {
...
@@ -340,13 +344,7 @@ expected<config_value::list> config_value::to_list() const {
config_value
::
dictionary
dict
;
config_value
::
dictionary
dict
;
if
(
detail
::
parse
(
x
,
dict
,
detail
::
require_opening_char
)
==
none
)
{
if
(
detail
::
parse
(
x
,
dict
,
detail
::
require_opening_char
)
==
none
)
{
tmp
.
clear
();
tmp
.
clear
();
for
(
const
auto
&
[
key
,
val
]
:
dict
)
{
dict_to_list
(
dict
,
tmp
);
list
kvp
;
kvp
.
reserve
(
2
);
kvp
.
emplace_back
(
key
);
kvp
.
emplace_back
(
val
);
tmp
.
emplace_back
(
std
::
move
(
kvp
));
}
return
result_type
{
std
::
move
(
tmp
)};
return
result_type
{
std
::
move
(
tmp
)};
}
}
std
::
string
msg
=
"cannot convert "
;
std
::
string
msg
=
"cannot convert "
;
...
@@ -355,15 +353,9 @@ expected<config_value::list> config_value::to_list() const {
...
@@ -355,15 +353,9 @@ expected<config_value::list> config_value::to_list() const {
return
result_type
{
make_error
(
sec
::
conversion_failed
,
std
::
move
(
msg
))};
return
result_type
{
make_error
(
sec
::
conversion_failed
,
std
::
move
(
msg
))};
},
},
[](
const
list
&
x
)
{
return
result_type
{
x
};
},
[](
const
list
&
x
)
{
return
result_type
{
x
};
},
[](
const
dictionary
&
x
)
{
[
dict_to_list
](
const
dictionary
&
x
)
{
list
tmp
;
list
tmp
;
for
(
const
auto
&
[
key
,
val
]
:
x
)
{
dict_to_list
(
x
,
tmp
);
list
kvp
;
kvp
.
reserve
(
2
);
kvp
.
emplace_back
(
key
);
kvp
.
emplace_back
(
val
);
tmp
.
emplace_back
(
std
::
move
(
kvp
));
}
return
result_type
{
std
::
move
(
tmp
)};
return
result_type
{
std
::
move
(
tmp
)};
});
});
return
visit
(
f
,
data_
);
return
visit
(
f
,
data_
);
...
...
libcaf_core/src/config_value_reader.cpp
View file @
ea11a6e9
...
@@ -593,6 +593,7 @@ bool config_value_reader::value(span<byte> bytes) {
...
@@ -593,6 +593,7 @@ bool config_value_reader::value(span<byte> bytes) {
bool
config_value_reader
::
fetch_object_type
(
const
settings
*
obj
,
bool
config_value_reader
::
fetch_object_type
(
const
settings
*
obj
,
type_id_t
&
type
)
{
type_id_t
&
type
)
{
if
(
auto
str
=
get_if
<
std
::
string
>
(
obj
,
"@type"
);
str
==
nullptr
)
{
if
(
auto
str
=
get_if
<
std
::
string
>
(
obj
,
"@type"
);
str
==
nullptr
)
{
// fetch_next_object_type only calls this function
type
=
type_id_v
<
config_value
::
dictionary
>
;
type
=
type_id_v
<
config_value
::
dictionary
>
;
return
true
;
return
true
;
}
else
if
(
auto
id
=
query_type_id
(
*
str
);
id
!=
invalid_type_id
)
{
}
else
if
(
auto
id
=
query_type_id
(
*
str
);
id
!=
invalid_type_id
)
{
...
...
libcaf_core/test/config_value.cpp
View file @
ea11a6e9
...
@@ -296,7 +296,7 @@ SCENARIO("get_as can convert config values to floating point numbers") {
...
@@ -296,7 +296,7 @@ SCENARIO("get_as can convert config values to floating point numbers") {
}
}
}
}
GIVEN
(
"config_values of null, URI, boolean, list or dictionary"
)
{
GIVEN
(
"config_values of null, URI, boolean, list or dictionary"
)
{
WHEN
(
"using get_as with
floating point
types"
)
{
WHEN
(
"using get_as with
integer
types"
)
{
THEN
(
"conversion fails"
)
{
THEN
(
"conversion fails"
)
{
CHECK_EQ
(
get_as
<
int64_t
>
(
cv_null
),
sec
::
conversion_failed
);
CHECK_EQ
(
get_as
<
int64_t
>
(
cv_null
),
sec
::
conversion_failed
);
CHECK_EQ
(
get_as
<
int64_t
>
(
cv_true
),
sec
::
conversion_failed
);
CHECK_EQ
(
get_as
<
int64_t
>
(
cv_true
),
sec
::
conversion_failed
);
...
@@ -323,7 +323,7 @@ SCENARIO("get_as can convert config values to timespans") {
...
@@ -323,7 +323,7 @@ SCENARIO("get_as can convert config values to timespans") {
THEN
(
"conversion fails"
)
{
THEN
(
"conversion fails"
)
{
CHECK_EQ
(
get_as
<
int64_t
>
(
x
),
sec
::
conversion_failed
);
CHECK_EQ
(
get_as
<
int64_t
>
(
x
),
sec
::
conversion_failed
);
CHECK_EQ
(
get_as
<
double
>
(
x
),
sec
::
conversion_failed
);
CHECK_EQ
(
get_as
<
double
>
(
x
),
sec
::
conversion_failed
);
//
CHECK_EQ(get_as<uri>(x), sec::conversion_failed);
CHECK_EQ
(
get_as
<
uri
>
(
x
),
sec
::
conversion_failed
);
CHECK_EQ
(
get_as
<
config_value
::
list
>
(
x
),
sec
::
conversion_failed
);
CHECK_EQ
(
get_as
<
config_value
::
list
>
(
x
),
sec
::
conversion_failed
);
CHECK_EQ
(
get_as
<
config_value
::
dictionary
>
(
x
),
sec
::
conversion_failed
);
CHECK_EQ
(
get_as
<
config_value
::
dictionary
>
(
x
),
sec
::
conversion_failed
);
}
}
...
...
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