/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include namespace apache { namespace thrift { namespace detail { template constexpr protocol::TType protocol_type_ill_formed_(T&&...) { if (!sizeof...(T)) { folly::throw_exception("ill-formed"); } return protocol::TType::T_STOP; } template struct protocol_type_ {}; template <> struct protocol_type_ { // clang-format off template static constexpr protocol::TType apply = std::is_same::value ? protocol::TType::T_BOOL : sizeof(Type) == 1 ? protocol::TType::T_BYTE : sizeof(Type) == 2 ? protocol::TType::T_I16 : sizeof(Type) == 4 ? protocol::TType::T_I32 : sizeof(Type) == 8 ? protocol::TType::T_I64 : protocol_type_ill_formed_(); // clang-format on }; template <> struct protocol_type_ { // clang-format off template static constexpr protocol::TType apply = sizeof(Type) == 4 ? protocol::TType::T_FLOAT : sizeof(Type) == 8 ? protocol::TType::T_DOUBLE : protocol_type_ill_formed_(); // clang-format on }; template <> struct protocol_type_ { template static constexpr protocol::TType apply = protocol::TType::T_STRING; }; template <> struct protocol_type_ { template static constexpr protocol::TType apply = protocol::TType::T_STRING; }; template <> struct protocol_type_ { template static constexpr protocol::TType apply = protocol::TType::T_I32; }; template <> struct protocol_type_ { template static constexpr protocol::TType apply = protocol::TType::T_STRUCT; }; template <> struct protocol_type_ { template static constexpr protocol::TType apply = protocol::TType::T_STRUCT; }; template struct protocol_type_> { template static constexpr protocol::TType apply = protocol::TType::T_LIST; }; template struct protocol_type_> { template static constexpr protocol::TType apply = protocol::TType::T_SET; }; template struct protocol_type_> { template static constexpr protocol::TType apply = protocol::TType::T_MAP; }; template struct protocol_type_> { template static constexpr protocol::TType apply = protocol_type_::template apply< std::remove_reference_t>>; }; } // namespace detail // protocol_type_v // protocol_type // // A trait variable and type to map from type-class and type to values of type // enum TType. template inline constexpr protocol::TType protocol_type_v = ::apache::thrift::detail::protocol_type_::template apply; template struct protocol_type // : std::integral_constant< // protocol::TType, protocol_type_v> {}; namespace detail { template struct fixed_cost_skip_ {}; template <> struct fixed_cost_skip_ { template static constexpr bool apply = true; }; template <> struct fixed_cost_skip_ { template static constexpr bool apply = true; }; template <> struct fixed_cost_skip_ { template static constexpr bool apply = !Protocol::kOmitsStringSizes(); }; template <> struct fixed_cost_skip_ { template static constexpr bool apply = !Protocol::kOmitsStringSizes(); }; template <> struct fixed_cost_skip_ { template static constexpr bool apply = true; }; template <> struct fixed_cost_skip_ { template static constexpr bool apply = false; }; template <> struct fixed_cost_skip_ { template static constexpr bool apply = false; }; template struct fixed_cost_skip_> { template static constexpr bool apply = !Protocol::kOmitsContainerSizes() && Protocol::fixedSizeInContainer( protocol_type_v) > 0; }; template struct fixed_cost_skip_> { template static constexpr bool apply = !Protocol::kOmitsContainerSizes() && Protocol::fixedSizeInContainer( protocol_type_v) > 0; }; template struct fixed_cost_skip_> { template static constexpr bool apply = !Protocol::kOmitsContainerSizes() && Protocol::fixedSizeInContainer( protocol_type_v) > 0 && Protocol::fixedSizeInContainer( protocol_type_v) > 0; }; } // namespace detail // fixed_cost_skip_v // // A trait variable reflecting whether the type has fixed cost to skip. // // For example, list has fixed cost to skip under Binary Protocol since // the list header includes the list length and since each list element has // fixed size. However, it is not cheap to skip under Compact Protocol since // list elements do not have fixed size. And it is not cheap to skip under // SimpleJson Protocol since the list header does not include the list length. template inline constexpr bool fixed_cost_skip_v = ::apache::thrift::detail::fixed_cost_skip_< TypeClass>::template apply; } // namespace thrift } // namespace apache