BlueToe
an alternative GATT/BLE implementation
Loading...
Searching...
No Matches
scattered_access.hpp
1#ifndef BLUETOE_SCATTERED_ACCESS_HPP
2#define BLUETOE_SCATTERED_ACCESS_HPP
3
4#include <bluetoe/attribute.hpp>
5#include <algorithm>
6
7namespace bluetoe {
8namespace details {
9
10 template < int Size >
11 std::uint8_t* copy( int offset, const std::uint8_t (&source)[ Size ], std::uint8_t* begin, std::uint8_t* end )
12 {
13 offset = std::max( 0, offset );
14 const int source_size = std::max( 0, Size - offset );
15 const int copy_size = std::min( source_size, std::max< int >( 0, end - begin ) );
16
17 std::copy( std::begin( source ) + offset, std::begin( source ) + offset + copy_size, begin );
18
19 return begin + copy_size;
20 }
21
22 template < int a_size, int b_size, int c_size >
23 void scattered_read_access(
24 int offset,
25 const std::uint8_t (&a)[ a_size ], const std::uint8_t (&b)[ b_size ], const std::uint8_t (&c)[ c_size ],
26 std::uint8_t* out_buffer, int out_buffer_size )
27 {
28 std::uint8_t* const end = out_buffer + out_buffer_size;
29 std::uint8_t* out = out_buffer;
30
31 out = copy( offset, a, out, end );
32 out = copy( offset - a_size, b, out, end );
33 copy( offset - a_size - b_size, c, out, end );
34 }
35}
36}
37#endif