v1_encoder.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "precompiled.hpp"
4 #include "encoder.hpp"
5 #include "v1_encoder.hpp"
6 #include "msg.hpp"
7 #include "wire.hpp"
8 
9 #include <limits.h>
10 
11 zmq::v1_encoder_t::v1_encoder_t (size_t bufsize_) :
12  encoder_base_t<v1_encoder_t> (bufsize_)
13 {
14  // Write 0 bytes to the batch and go to message_ready state.
15  next_step (NULL, 0, &v1_encoder_t::message_ready, true);
16 }
17 
18 zmq::v1_encoder_t::~v1_encoder_t ()
19 {
20 }
21 
22 void zmq::v1_encoder_t::size_ready ()
23 {
24  // Write message body into the buffer.
25  next_step (in_progress ()->data (), in_progress ()->size (),
26  &v1_encoder_t::message_ready, true);
27 }
28 
29 void zmq::v1_encoder_t::message_ready ()
30 {
31  size_t header_size = 2; // flags byte + size byte
32  // Get the message size.
33  size_t size = in_progress ()->size ();
34 
35  // Account for the 'flags' byte.
36  size++;
37 
38  // Account for the subscribe/cancel byte.
39  if (in_progress ()->is_subscribe () || in_progress ()->is_cancel ())
40  size++;
41 
42  // For messages less than 255 bytes long, write one byte of message size.
43  // For longer messages write 0xff escape character followed by 8-byte
44  // message size. In both cases 'flags' field follows.
45  if (size < UCHAR_MAX) {
46  _tmpbuf[0] = static_cast<unsigned char> (size);
47  _tmpbuf[1] = (in_progress ()->flags () & msg_t::more);
48  } else {
49  _tmpbuf[0] = UCHAR_MAX;
50  put_uint64 (_tmpbuf + 1, size);
51  _tmpbuf[9] = (in_progress ()->flags () & msg_t::more);
52  header_size = 10;
53  }
54 
55  // Encode the subscribe/cancel byte. This is done in the encoder as
56  // opposed to when the subscribe message is created to allow different
57  // protocol behaviour on the wire in the v3.1 and legacy encoders.
58  // It results in the work being done multiple times in case the sub
59  // is sending the subscription/cancel to multiple pubs, but it cannot
60  // be avoided. This processing can be moved to xsub once support for
61  // ZMTP < 3.1 is dropped.
62  if (in_progress ()->is_subscribe ())
63  _tmpbuf[header_size++] = 1;
64  else if (in_progress ()->is_cancel ())
65  _tmpbuf[header_size++] = 0;
66 
67  next_step (_tmpbuf, header_size, &v1_encoder_t::size_ready, false);
68 }
NULL
NULL
Definition: test_security_zap.cpp:405
precompiled.hpp
wire.hpp
v1_encoder.hpp
size
#define size
Definition: glcorearb.h:2944
msg.hpp
zmq::put_uint64
void put_uint64(unsigned char *buffer_, uint64_t value_)
Definition: wire.hpp:51
zmq::msg_t::more
@ more
Definition: msg.hpp:55
size
GLsizeiptr size
Definition: glcorearb.h:2943
encoder.hpp
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: glcorearb.h:2879


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:01