CARLA
MsgPack.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/Buffer.h"
10 
11 #include <rpc/msgpack.hpp>
12 
13 namespace carla {
14 
15  class MsgPack {
16  public:
17 
18  template <typename T>
19  static Buffer Pack(const T &obj) {
20  namespace mp = ::clmdep_msgpack;
21  mp::sbuffer sbuf;
22  mp::pack(sbuf, obj);
23  return Buffer(reinterpret_cast<const unsigned char *>(sbuf.data()), sbuf.size());
24  }
25 
26  template <typename T>
27  static T UnPack(const Buffer &buffer) {
28  namespace mp = ::clmdep_msgpack;
29  return mp::unpack(reinterpret_cast<const char *>(buffer.data()), buffer.size()).template as<T>();
30  }
31 
32  template <typename T>
33  static T UnPack(const unsigned char *data, size_t size) {
34  namespace mp = ::clmdep_msgpack;
35  return mp::unpack(reinterpret_cast<const char *>(data), size).template as<T>();
36  }
37  };
38 
39 } // namespace carla
const value_type * data() const noexcept
Direct access to the allocated memory or nullptr if no memory is allocated.
Definition: carla/Buffer.h:156
static Buffer Pack(const T &obj)
Definition: MsgPack.h:19
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
static T UnPack(const unsigned char *data, size_t size)
Definition: MsgPack.h:33
A piece of raw data.
Definition: carla/Buffer.h:42
size_type size() const noexcept
Definition: carla/Buffer.h:197
static T UnPack(const Buffer &buffer)
Definition: MsgPack.h:27