1 /* 2 * Copyright 2019 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 17 #pragma once 18 19 #include <array> 20 21 #include "packet/bit_inserter.h" 22 #include "packet/iterator.h" 23 24 namespace bluetooth { 25 namespace packet { 26 // Checks a custom type has all the necessary functions with the correct signatures. 27 template <typename T, bool packet_little_endian> 28 class CustomTypeChecker { 29 public: 30 template <class C, void (C::*)(BitInserter&) const> 31 struct SerializeChecker {}; 32 33 template <class C, size_t (C::*)() const> 34 struct SizeChecker {}; 35 36 template <class C, bool little_endian, std::optional<Iterator<little_endian>> (*)(C* vec, Iterator<little_endian> it)> 37 struct ParseChecker {}; 38 39 template <class C, std::string (C::*)() const> 40 struct ToStringChecker {}; 41 42 template <class C, bool little_endian> 43 static int Test(SerializeChecker<C, &C::Serialize>*, SizeChecker<C, &C::size>*, 44 ParseChecker<C, little_endian, &C::Parse>*, ToStringChecker<C, &C::ToString>*); 45 46 template <class C, bool little_endian> 47 static char Test(...); 48 49 static constexpr bool value = (sizeof(Test<T, packet_little_endian>(0, 0, 0, 0)) == sizeof(int)); 50 }; 51 } // namespace packet 52 } // namespace bluetooth 53