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
6f84e70b
Commit
6f84e70b
authored
Dec 09, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add from_string function to node_id
parent
5fbf631a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
1 deletion
+52
-1
cash
cash
+1
-1
libcaf_core/caf/node_id.hpp
libcaf_core/caf/node_id.hpp
+2
-0
libcaf_core/src/node_id.cpp
libcaf_core/src/node_id.cpp
+49
-0
No files found.
cash
@
d12586c0
Subproject commit
08cc54612466e68f35b9b2f6ecaa8853914d3574
Subproject commit
d12586c073d9336860975addffb190d644f163b0
libcaf_core/caf/node_id.hpp
View file @
6f84e70b
...
@@ -144,6 +144,8 @@ public:
...
@@ -144,6 +144,8 @@ public:
friend
void
serialize
(
deserializer
&
source
,
node_id
&
x
,
const
unsigned
int
);
friend
void
serialize
(
deserializer
&
source
,
node_id
&
x
,
const
unsigned
int
);
void
from_string
(
const
std
::
string
&
str
);
/// @endcond
/// @endcond
private:
private:
...
...
libcaf_core/src/node_id.cpp
View file @
6f84e70b
...
@@ -205,6 +205,55 @@ void serialize(deserializer& source, node_id& x, const unsigned int) {
...
@@ -205,6 +205,55 @@ void serialize(deserializer& source, node_id& x, const unsigned int) {
}
}
}
}
namespace
{
inline
uint8_t
hex_nibble
(
char
c
)
{
return
static_cast
<
uint8_t
>
(
c
>=
'0'
&&
c
<=
'9'
?
c
-
'0'
:
(
c
>=
'a'
&&
c
<=
'f'
?
(
c
-
'a'
)
+
10
:
(
c
-
'A'
)
+
10
));
};
}
// namespace <anonymous>
void
node_id
::
from_string
(
const
std
::
string
&
str
)
{
data_
.
reset
();
if
(
str
==
"<invalid-node>"
)
return
;
static
constexpr
size_t
hexstr_size
=
host_id_size
*
2
;
// node id format is: "[0-9a-zA-Z]{40}:[0-9]+"
if
(
str
.
size
()
<
hexstr_size
+
2
)
return
;
auto
beg
=
str
.
begin
();
auto
sep
=
beg
+
hexstr_size
;
// separator ':' / end of hex-string
auto
eos
=
str
.
end
();
// end-of-string
if
(
*
sep
!=
':'
)
return
;
if
(
!
std
::
all_of
(
beg
,
sep
,
::
isxdigit
))
return
;
if
(
!
std
::
all_of
(
sep
+
1
,
eos
,
::
isdigit
))
return
;
// iterate two digits in the input string as one byte in hex format
struct
hex_byte_iter
{
std
::
string
::
const_iterator
i
;
uint8_t
operator
*
()
const
{
return
(
hex_nibble
(
*
i
)
<<
4
)
|
hex_nibble
(
*
(
i
+
1
));
}
hex_byte_iter
&
operator
++
()
{
i
+=
2
;
return
*
this
;
}
bool
operator
!=
(
const
hex_byte_iter
&
x
)
const
{
return
i
!=
x
.
i
;
}
};
hex_byte_iter
first
{
beg
};
hex_byte_iter
last
{
sep
};
data_
.
reset
(
new
data
);
std
::
copy
(
first
,
last
,
data_
->
host_
.
begin
());
data_
->
pid_
=
static_cast
<
uint32_t
>
(
atoll
(
&*
(
sep
+
1
)));
}
std
::
string
to_string
(
const
node_id
&
x
)
{
std
::
string
to_string
(
const
node_id
&
x
)
{
if
(
!
x
)
if
(
!
x
)
return
"<invalid-node>"
;
return
"<invalid-node>"
;
...
...
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