CARLA
Token.cpp
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 
8 
9 #include "carla/Exception.h"
10 
11 #include <cstring>
12 #include <exception>
13 
14 namespace carla {
15 namespace streaming {
16 namespace detail {
17 
18  void token_type::set_address(const boost::asio::ip::address &addr) {
19  if (addr.is_v4()) {
21  _token.address.v4 = addr.to_v4().to_bytes();
22  } else if (addr.is_v6()) {
24  _token.address.v6 = addr.to_v6().to_bytes();
25  } else {
26  throw_exception(std::invalid_argument("invalid ip address!"));
27  }
28  }
29 
31  std::memcpy(&_token, &rhs.data[0u], sizeof(_token));
32  }
33 
34  token_type::operator Token() const {
35  Token token;
36  std::memcpy(&token.data[0u], &_token, token.data.size());
37  return token;
38  }
39 
40  boost::asio::ip::address token_type::get_address() const {
42  return boost::asio::ip::address_v4(_token.address.v4);
43  }
44  return boost::asio::ip::address_v6(_token.address.v6);
45  }
46 
47 } // namespace detail
48 } // namespace streaming
49 } // namespace carla
std::array< unsigned char, 24u > data
Definition: Token.h:20
void throw_exception(const std::exception &e)
Definition: Carla.cpp:135
void set_address(const boost::asio::ip::address &addr)
Definition: Token.cpp:18
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
A token that uniquely identify a stream.
Definition: Token.h:17
enum carla::streaming::detail::token_data::address address_type
boost::asio::ip::address get_address() const
Definition: Token.cpp:40