C++ Pixels Library For Windows
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 <cstdint>
9#include <vector>
10#include <algorithm> // sort, includes
11
12namespace Systemic::BluetoothLE::Internal
13{
22 template <typename T>
23 bool isSubset(std::vector<T> subset, std::vector<T> superset)
24 {
25 std::sort(subset.begin(), subset.end());
26 std::sort(superset.begin(), superset.end());
27 return std::includes(superset.begin(), superset.end(), subset.begin(), subset.end());
28 }
29
36 inline
37 std::vector<uint8_t> dataBufferToBytesVector(winrt::Windows::Storage::Streams::IBuffer buffer)
38 {
39 using namespace winrt::Windows::Storage::Streams;
40
41 std::vector<uint8_t> outData;
42 outData.resize(buffer.Length());
43 auto reader = DataReader::FromBuffer(buffer);
44 reader.ReadBytes(outData);
45 return outData;
46 }
47
54 inline
55 winrt::Windows::Storage::Streams::IBuffer bytesVectorToDataBuffer(const std::vector<std::uint8_t>& data)
56 {
57 using namespace winrt::Windows::Storage::Streams;
58
59 //InMemoryRandomAccessStream stream{};
60 DataWriter dataWriter{}; // { stream };
61 dataWriter.ByteOrder(ByteOrder::LittleEndian);
62 dataWriter.WriteBytes(data);
63 return dataWriter.DetachBuffer();
64 }
65}