raw_decoder.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "precompiled.hpp"
4 #include <stdlib.h>
5 #include <string.h>
6 
7 #include "raw_decoder.hpp"
8 #include "err.hpp"
9 
10 zmq::raw_decoder_t::raw_decoder_t (size_t bufsize_) : _allocator (bufsize_, 1)
11 {
12  const int rc = _in_progress.init ();
13  errno_assert (rc == 0);
14 }
15 
16 zmq::raw_decoder_t::~raw_decoder_t ()
17 {
18  const int rc = _in_progress.close ();
19  errno_assert (rc == 0);
20 }
21 
22 void zmq::raw_decoder_t::get_buffer (unsigned char **data_, size_t *size_)
23 {
24  *data_ = _allocator.allocate ();
25  *size_ = _allocator.size ();
26 }
27 
28 int zmq::raw_decoder_t::decode (const uint8_t *data_,
29  size_t size_,
30  size_t &bytes_used_)
31 {
32  const int rc =
33  _in_progress.init (const_cast<unsigned char *> (data_), size_,
34  shared_message_memory_allocator::call_dec_ref,
35  _allocator.buffer (), _allocator.provide_content ());
36 
37  // if the buffer serves as memory for a zero-copy message, release it
38  // and allocate a new buffer in get_buffer for the next decode
39  if (_in_progress.is_zcmsg ()) {
40  _allocator.advance_content ();
41  _allocator.release ();
42  }
43 
44  errno_assert (rc != -1);
45  bytes_used_ = size_;
46  return 1;
47 }
data_
StringPiece data_
Definition: bytestream_unittest.cc:60
precompiled.hpp
errno_assert
#define errno_assert(x)
Definition: err.hpp:113
raw_decoder.hpp
err.hpp


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:58