• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15 
16 #include <type_traits>
17 
18 #include "pw_span/span.h"
19 
20 /// Creates a pw::span on the HCI portion of an H4 buffer.
21 template <typename C>
H4HciSubspan(C && container)22 constexpr inline auto H4HciSubspan(C&& container) {
23   return pw::span(container.data() + 1, container.size() - 1);
24 }
25 
26 // Create an Emboss View or Writer from a pw::span value or reference. The
27 // Emboss type is determined by the template's first parameter.
28 // Unlike the Emboss `Make*View` creation methods, this function accepts a
29 // reference so it can be used with rvalues. This is ok to do with pw::span
30 // since it doesn't own its underlying data. Another key difference is the
31 // caller explicitly chooses if they want a View or a Writer using the first
32 // template argument.
33 template <
34     typename EmbossT,
35     typename ContainerT,
36     typename = std::enable_if<std::is_base_of_v<pw::span<uint8_t>, ContainerT>>>
MakeEmboss(ContainerT && buffer)37 constexpr inline EmbossT MakeEmboss(ContainerT&& buffer) {
38   return EmbossT(buffer.data(), buffer.size());
39 }
40