diff --git a/src/encoder.hpp b/src/encoder.hpp index 93b654bd..aac27515 100644 --- a/src/encoder.hpp +++ b/src/encoder.hpp @@ -54,14 +54,14 @@ namespace zmq template class encoder_base_t : public i_encoder { public: - inline encoder_base_t (size_t bufsize_) : + inline explicit encoder_base_t (size_t bufsize_) : _write_pos (0), _to_write (0), _next (NULL), _new_msg_flag (false), _buf_size (bufsize_), _buf (static_cast (malloc (bufsize_))), - in_progress (NULL) + _in_progress (NULL) { alloc_assert (_buf); } @@ -78,7 +78,7 @@ template 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 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 (this)->*_next) (); @@ -130,8 +130,8 @@ template 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 (this)->*_next) (); } @@ -152,6 +152,8 @@ template 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 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; }; } diff --git a/src/raw_encoder.cpp b/src/raw_encoder.cpp index fa510963..39c7633e 100644 --- a/src/raw_encoder.cpp +++ b/src/raw_encoder.cpp @@ -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); } diff --git a/src/v1_encoder.cpp b/src/v1_encoder.cpp index cc78d417..8ef22ae7 100644 --- a/src/v1_encoder.cpp +++ b/src/v1_encoder.cpp @@ -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 (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); } } diff --git a/src/v2_encoder.cpp b/src/v2_encoder.cpp index 1a869068..88f005a9 100644 --- a/src/v2_encoder.cpp +++ b/src/v2_encoder.cpp @@ -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); }