1#ifndef BLUETOE_SCATTERED_ACCESS_HPP
2#define BLUETOE_SCATTERED_ACCESS_HPP
4#include <bluetoe/attribute.hpp>
11 std::uint8_t* copy(
int offset,
const std::uint8_t (&source)[ Size ], std::uint8_t* begin, std::uint8_t* end )
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 ) );
17 std::copy( std::begin( source ) + offset, std::begin( source ) + offset + copy_size, begin );
19 return begin + copy_size;
22 template <
int a_size,
int b_size,
int c_size >
23 void scattered_read_access(
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 )
28 std::uint8_t*
const end = out_buffer + out_buffer_size;
29 std::uint8_t* out = out_buffer;
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 );