BlueToe
an alternative GATT/BLE implementation
Loading...
Searching...
No Matches
default_pdu_layout.hpp
1#ifndef BLUETOE_LINK_LAYER_DEFAULT_PDU_LAYOUT_HPP
2#define BLUETOE_LINK_LAYER_DEFAULT_PDU_LAYOUT_HPP
3
4#include <bluetoe/bits.hpp>
5#include <bluetoe/buffer.hpp>
6
7namespace bluetoe {
8namespace link_layer {
9
10 namespace details {
11 // usefull overloads
12 template < class Base >
13 struct layout_base
14 {
15 static std::uint16_t header( const read_buffer& pdu )
16 {
17 assert( pdu.size >= Base::data_channel_pdu_memory_size( 0 ) );
18
19 return Base::header( pdu.buffer );
20 }
21
22 static std::uint16_t header( const write_buffer& pdu )
23 {
24 assert( pdu.size >= Base::data_channel_pdu_memory_size( 0 ) );
25
26 return Base::header( pdu.buffer );
27 }
28
29 static void header( const read_buffer& pdu, std::uint16_t header_value )
30 {
31 assert( pdu.size >= Base::data_channel_pdu_memory_size( 0 ) );
32
33 Base::header( pdu.buffer, header_value );
34 }
35 };
36 }
42 struct default_pdu_layout : details::layout_base< default_pdu_layout >{
46 static constexpr std::size_t header_size = sizeof( std::uint16_t );
47
48 using details::layout_base< default_pdu_layout >::header;
49
53 static std::uint16_t header( const std::uint8_t* pdu )
54 {
55 return ::bluetoe::details::read_16bit( pdu );
56 }
57
61 static void header( std::uint8_t* pdu, std::uint16_t header_value )
62 {
63 ::bluetoe::details::write_16bit( pdu, header_value );
64 }
65
71 static std::pair< std::uint8_t*, std::uint8_t* > body( const read_buffer& pdu )
72 {
73 assert( pdu.size >= header_size );
74
75 return { &pdu.buffer[ header_size ], &pdu.buffer[ pdu.size ] };
76 }
77
81 static std::pair< const std::uint8_t*, const std::uint8_t* > body( const write_buffer& pdu )
82 {
83 assert( pdu.size >= header_size );
84
85 return { &pdu.buffer[ header_size ], &pdu.buffer[ pdu.size ] };
86 }
87
92 static constexpr std::size_t data_channel_pdu_memory_size( std::size_t payload_size )
93 {
94 return header_size + payload_size;
95 }
96 };
97
103 template < typename Radio >
109 };
110
111}
112}
113
114#endif