Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
573815da
Commit
573815da
authored
May 30, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: protected data member in encoder_base_t
Solution: encapsulate data member properly
parent
088fd65b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
20 deletions
+21
-20
encoder.hpp
src/encoder.hpp
+11
-10
raw_encoder.cpp
src/raw_encoder.cpp
+1
-1
v1_encoder.cpp
src/v1_encoder.cpp
+4
-4
v2_encoder.cpp
src/v2_encoder.cpp
+5
-5
No files found.
src/encoder.hpp
View file @
573815da
...
...
@@ -54,14 +54,14 @@ namespace zmq
template
<
typename
T
>
class
encoder_base_t
:
public
i_encoder
{
public
:
inline
encoder_base_t
(
size_t
bufsize_
)
:
inline
e
xplicit
e
ncoder_base_t
(
size_t
bufsize_
)
:
_write_pos
(
0
),
_to_write
(
0
),
_next
(
NULL
),
_new_msg_flag
(
false
),
_buf_size
(
bufsize_
),
_buf
(
static_cast
<
unsigned
char
*>
(
malloc
(
bufsize_
))),
in_progress
(
NULL
)
_
in_progress
(
NULL
)
{
alloc_assert
(
_buf
);
}
...
...
@@ -78,7 +78,7 @@ template <typename T> class encoder_base_t : public i_encoder
unsigned
char
*
buffer
=
!*
data_
?
_buf
:
*
data_
;
size_t
buffersize
=
!*
data_
?
_buf_size
:
size_
;
if
(
in_progress
==
NULL
)
if
(
in_progress
()
==
NULL
)
return
0
;
size_t
pos
=
0
;
...
...
@@ -88,11 +88,11 @@ template <typename T> class encoder_base_t : public i_encoder
// in the buffer.
if
(
!
_to_write
)
{
if
(
_new_msg_flag
)
{
int
rc
=
in_progress
->
close
();
int
rc
=
_
in_progress
->
close
();
errno_assert
(
rc
==
0
);
rc
=
in_progress
->
init
();
rc
=
_
in_progress
->
init
();
errno_assert
(
rc
==
0
);
in_progress
=
NULL
;
_
in_progress
=
NULL
;
break
;
}
(
static_cast
<
T
*>
(
this
)
->*
_next
)
();
...
...
@@ -130,8 +130,8 @@ template <typename T> class encoder_base_t : public i_encoder
void
load_msg
(
msg_t
*
msg_
)
{
zmq_assert
(
in_progress
==
NULL
);
in_progress
=
msg_
;
zmq_assert
(
in_progress
()
==
NULL
);
_
in_progress
=
msg_
;
(
static_cast
<
T
*>
(
this
)
->*
_next
)
();
}
...
...
@@ -152,6 +152,8 @@ template <typename T> class encoder_base_t : public i_encoder
_new_msg_flag
=
new_msg_flag_
;
}
msg_t
*
in_progress
()
{
return
_in_progress
;
}
private
:
// Where to get the data to write from.
unsigned
char
*
_write_pos
;
...
...
@@ -172,8 +174,7 @@ template <typename T> class encoder_base_t : public i_encoder
encoder_base_t
(
const
encoder_base_t
&
);
void
operator
=
(
const
encoder_base_t
&
);
protected
:
msg_t
*
in_progress
;
msg_t
*
_in_progress
;
};
}
...
...
src/raw_encoder.cpp
View file @
573815da
...
...
@@ -45,6 +45,6 @@ zmq::raw_encoder_t::~raw_encoder_t ()
void
zmq
::
raw_encoder_t
::
raw_message_ready
()
{
next_step
(
in_progress
->
data
(),
in_progress
->
size
(),
next_step
(
in_progress
()
->
data
(),
in_progress
()
->
size
(),
&
raw_encoder_t
::
raw_message_ready
,
true
);
}
src/v1_encoder.cpp
View file @
573815da
...
...
@@ -49,14 +49,14 @@ zmq::v1_encoder_t::~v1_encoder_t ()
void
zmq
::
v1_encoder_t
::
size_ready
()
{
// Write message body into the buffer.
next_step
(
in_progress
->
data
(),
in_progress
->
size
(),
next_step
(
in_progress
()
->
data
(),
in_progress
()
->
size
(),
&
v1_encoder_t
::
message_ready
,
true
);
}
void
zmq
::
v1_encoder_t
::
message_ready
()
{
// Get the message size.
size_t
size
=
in_progress
->
size
();
size_t
size
=
in_progress
()
->
size
();
// Account for the 'flags' byte.
size
++
;
...
...
@@ -66,12 +66,12 @@ void zmq::v1_encoder_t::message_ready ()
// message size. In both cases 'flags' field follows.
if
(
size
<
UCHAR_MAX
)
{
_tmpbuf
[
0
]
=
static_cast
<
unsigned
char
>
(
size
);
_tmpbuf
[
1
]
=
(
in_progress
->
flags
()
&
msg_t
::
more
);
_tmpbuf
[
1
]
=
(
in_progress
()
->
flags
()
&
msg_t
::
more
);
next_step
(
_tmpbuf
,
2
,
&
v1_encoder_t
::
size_ready
,
false
);
}
else
{
_tmpbuf
[
0
]
=
UCHAR_MAX
;
put_uint64
(
_tmpbuf
+
1
,
size
);
_tmpbuf
[
9
]
=
(
in_progress
->
flags
()
&
msg_t
::
more
);
_tmpbuf
[
9
]
=
(
in_progress
()
->
flags
()
&
msg_t
::
more
);
next_step
(
_tmpbuf
,
10
,
&
v1_encoder_t
::
size_ready
,
false
);
}
}
src/v2_encoder.cpp
View file @
573815da
...
...
@@ -52,17 +52,17 @@ void zmq::v2_encoder_t::message_ready ()
// Encode flags.
unsigned
char
&
protocol_flags
=
_tmp_buf
[
0
];
protocol_flags
=
0
;
if
(
in_progress
->
flags
()
&
msg_t
::
more
)
if
(
in_progress
()
->
flags
()
&
msg_t
::
more
)
protocol_flags
|=
v2_protocol_t
::
more_flag
;
if
(
in_progress
->
size
()
>
UCHAR_MAX
)
if
(
in_progress
()
->
size
()
>
UCHAR_MAX
)
protocol_flags
|=
v2_protocol_t
::
large_flag
;
if
(
in_progress
->
flags
()
&
msg_t
::
command
)
if
(
in_progress
()
->
flags
()
&
msg_t
::
command
)
protocol_flags
|=
v2_protocol_t
::
command_flag
;
// Encode the message length. For messages less then 256 bytes,
// the length is encoded as 8-bit unsigned integer. For larger
// messages, 64-bit unsigned integer in network byte order is used.
const
size_t
size
=
in_progress
->
size
();
const
size_t
size
=
in_progress
()
->
size
();
if
(
unlikely
(
size
>
UCHAR_MAX
))
{
put_uint64
(
_tmp_buf
+
1
,
size
);
next_step
(
_tmp_buf
,
9
,
&
v2_encoder_t
::
size_ready
,
false
);
...
...
@@ -75,6 +75,6 @@ void zmq::v2_encoder_t::message_ready ()
void
zmq
::
v2_encoder_t
::
size_ready
()
{
// Write message body into the buffer.
next_step
(
in_progress
->
data
(),
in_progress
->
size
(),
next_step
(
in_progress
()
->
data
(),
in_progress
()
->
size
(),
&
v2_encoder_t
::
message_ready
,
true
);
}
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