Pixels Plugin for Unity
Enable communications with Pixels dice using Bluetooth Low Energy.
Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <algorithm> // sort, includes
9
10namespace Systemic::BluetoothLE::Internal
11{
20 template <typename T>
21 bool isSubset(std::vector<T> subset, std::vector<T> superset)
22 {
23 std::sort(subset.begin(), subset.end());
24 std::sort(superset.begin(), superset.end());
25 return std::includes(superset.begin(), superset.end(), subset.begin(), subset.end());
26 }
27
28 template <typename T>
29 bool isOverlapping(const std::vector<T>& v0, const std::vector<T>& v1)
30 {
31 return std::find_first_of(v0.begin(), v0.end(), v1.begin(), v1.end()) != v0.end();
32 }
33
40 inline
41 std::vector<uint8_t> dataBufferToBytesVector(winrt::Windows::Storage::Streams::IBuffer buffer)
42 {
43 using namespace winrt::Windows::Storage::Streams;
44
45 std::vector<uint8_t> outData;
46 outData.resize(buffer.Length());
47 auto reader = DataReader::FromBuffer(buffer);
48 reader.ReadBytes(outData);
49 return outData;
50 }
51
58 inline
59 winrt::Windows::Storage::Streams::IBuffer bytesVectorToDataBuffer(const std::vector<std::uint8_t>& data)
60 {
61 using namespace winrt::Windows::Storage::Streams;
62
63 //InMemoryRandomAccessStream stream{};
64 DataWriter dataWriter{}; // { stream };
65 dataWriter.ByteOrder(ByteOrder::LittleEndian);
66 dataWriter.WriteBytes(data);
67 return dataWriter.DetachBuffer();
68 }
69}