NAP
udppacket.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // External includes
8 #include <nap/core.h>
9 
10 namespace nap
11 {
13 
18  struct NAPAPI UDPPacket final
19  {
20  public:
21  // Default constructor
22  UDPPacket() = default;
23 
24  // Default copy constructor
25  UDPPacket(const UDPPacket& other) = default;
26 
27  // Default copy assignment operator
28  UDPPacket& operator=(const UDPPacket& other) = default;
29 
30  // Move constructor
31  UDPPacket(UDPPacket&& other) noexcept { mBuffer = std::move(other.mBuffer); }
32 
33  // Move assignment operator
34  UDPPacket& operator=(UDPPacket&& other) noexcept { mBuffer = std::move(other.mBuffer); return *this; }
35 
39  UDPPacket(const std::string& string) noexcept { std::copy(string.begin(), string.end(), std::back_inserter(mBuffer)); }
40 
45  UDPPacket(std::vector<nap::uint8>&& buffer) : mBuffer(std::move(buffer)){}
46 
51  UDPPacket(const std::vector<nap::uint8>& buffer) : mBuffer(buffer) {}
52 
57  const std::vector<nap::uint8>& data() const { return mBuffer; }
58 
63  size_t size() const{ return mBuffer.size(); }
64 
68  std::string toString() const{ return std::string(mBuffer.begin(), mBuffer.end()); }
69  private:
70  std::vector<nap::uint8> mBuffer;
71  };
72 }
nap::UDPPacket::data
const std::vector< nap::uint8 > & data() const
Definition: udppacket.h:57
nap::UDPPacket::UDPPacket
UDPPacket(UDPPacket &&other) noexcept
Definition: udppacket.h:31
nap::UDPPacket::toString
std::string toString() const
Definition: udppacket.h:68
nap::UDPPacket::size
size_t size() const
Definition: udppacket.h:63
nap::UDPPacket::UDPPacket
UDPPacket(const std::string &string) noexcept
Definition: udppacket.h:39
nap::UDPPacket::UDPPacket
UDPPacket(const std::vector< nap::uint8 > &buffer)
Definition: udppacket.h:51
nap
Definition: templateapp.h:17
nap::UDPPacket::operator=
UDPPacket & operator=(UDPPacket &&other) noexcept
Definition: udppacket.h:34
nap::UDPPacket::UDPPacket
UDPPacket(std::vector< nap::uint8 > &&buffer)
Definition: udppacket.h:45
nap::UDPPacket
Definition: udppacket.h:18