• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <cstdint>
19 #include <type_traits>
20 
21 namespace bluetooth {
22 namespace packet {
23 
24 template <typename T>
25 class CustomFieldFixedSizeInterface {
26  public:
27   virtual ~CustomFieldFixedSizeInterface() = default;
28   // Get a pointer to a modifiable and readable continuous array of data
29   virtual uint8_t* data() = 0;
30   virtual const uint8_t* data() const = 0;
31   // Get the length of underlying data array, data() + length() would be invalid
32   // subclass T must have kLength variable defined
length()33   static constexpr size_t length() {
34     static_assert(
35         std::is_same_v<decltype(T::kLength), const size_t>, "T::kLength must be const size_t or constexpr size_t");
36     static_assert(std::is_const_v<decltype(T::kLength)>, "T::kLength must be const");
37     return T::kLength;
38   };
39 };
40 
41 }  // namespace packet
42 }  // namespace bluetooth