/* * 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. */ // Operations supported by all ThriftType values. #pragma once #include #include namespace apache { namespace thrift { namespace op { /// Returns true iff the given value is 'empty', and not serialized in a /// 'terse' context. /// /// Some types cannot represent an 'empty' value. For example, /// a non-terse, non-optional field always serializes to a non-empty buffer, /// thus any struct with such a field, can never be 'empty'. /// In such cases, it is possible to deserialize from an empty buffer, but it is /// impossible to serialize to an empty buffer. /// /// For example: /// * isEmpty(0) -> true /// * isEmpty(1) -> false /// * isEmpty>({}) -> true /// * isEmpty>({0}) -> false template inline constexpr detail::IsEmpty isEmpty{}; /// Returns the default for the given type. /// /// Includes all 'custom' defaults set on fields within structured types. /// /// For example: /// * getDefault>() -> {} /// * getDefault() -> "" /// * getDefault() -> 0 template inline constexpr detail::GetDefault> getDefault{}; /// Returns the 'intrinsic' default for the given type. /// /// Ignores all 'custom' defaults set on fields within structured types. /// /// For example: /// * getIntrinsicDefault>() -> {} /// * getIntrinsicDefault() -> "" /// * getIntrinsicDefault() -> 0 template inline constexpr detail::GetIntrinsicDefault> getIntrinsicDefault{}; /// Clears the given value, leaving it equal to its intrinsic default. /// /// For example: /// * clear<>(myInt) // sets myInt = 0. /// * clear>(myIntSet) // calls myIntSet.clear() /// * clear(myStruct) // calls myStruct.foo().reset() template inline constexpr detail::Clear clear{}; /// Clears the given field, setting the field to initial state. /// /// For example: /// * clear_field(foo.field(), foo) /// // clears foo.field().value() to the intrinsic default value. /// * clear_field(foo.optional_field(), foo) /// // calls foo.optional_field().reset(). /// // TODO(afuller): Migrate all usage to op::clear(struct) and remove. template inline constexpr detail::ClearField clear_field{}; } // namespace op } // namespace thrift } // namespace apache