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
c42dcaf0
Commit
c42dcaf0
authored
Feb 15, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement varbyte encoding on binary serializers
parent
5459caf1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
libcaf_core/src/binary_deserializer.cpp
libcaf_core/src/binary_deserializer.cpp
+11
-4
libcaf_core/src/binary_serializer.cpp
libcaf_core/src/binary_serializer.cpp
+13
-2
No files found.
libcaf_core/src/binary_deserializer.cpp
View file @
c42dcaf0
...
...
@@ -86,10 +86,17 @@ error binary_deserializer::end_object() {
}
error
binary_deserializer
::
begin_sequence
(
size_t
&
list_size
)
{
auto
s
=
static_cast
<
uint32_t
>
(
list_size
);
if
(
auto
err
=
apply
(
s
))
return
err
;
list_size
=
s
;
// Use varbyte encoding to compress sequence size on the wire.
uint32_t
x
=
0
;
int
n
=
0
;
uint8_t
low7
;
do
{
if
(
auto
err
=
apply_impl
(
low7
))
return
err
;
x
|=
static_cast
<
uint32_t
>
((
low7
&
0x7F
))
<<
(
7
*
n
);
++
n
;
}
while
(
low7
&
0x80
);
list_size
=
x
;
return
none
;
}
...
...
libcaf_core/src/binary_serializer.cpp
View file @
c42dcaf0
...
...
@@ -71,8 +71,19 @@ error binary_serializer::end_object() {
}
error
binary_serializer
::
begin_sequence
(
size_t
&
list_size
)
{
auto
s
=
static_cast
<
uint32_t
>
(
list_size
);
return
apply
(
s
);
// Use varbyte encoding to compress sequence size on the wire.
// For 64-bit values, the encoded representation cannot get larger than 10
// bytes. A scratch space of 16 bytes suffices as upper bound.
uint8_t
buf
[
16
];
auto
i
=
buf
;
auto
x
=
static_cast
<
uint32_t
>
(
list_size
);
while
(
x
>
0x7f
)
{
*
i
++
=
(
static_cast
<
uint8_t
>
(
x
)
&
0x7f
)
|
0x80
;
x
>>=
7
;
}
*
i
++
=
static_cast
<
uint8_t
>
(
x
)
&
0x7f
;
apply_raw
(
static_cast
<
size_t
>
(
i
-
buf
),
buf
);
return
none
;
}
error
binary_serializer
::
end_sequence
()
{
...
...
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