/* * 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 #include namespace facebook::sbe::test { class CustomerLookupHandler : public apache::thrift::ServiceHandler { public: explicit CustomerLookupHandler( folly::F14FastMap&& customers); folly::coro::Task> co_lookupOne( std::unique_ptr p_request) override { co_return doLookupOne(std::move(p_request)); } folly::coro::Task> co_lookupMany( std::unique_ptr p_request) override { co_return doLookupMany(std::move(p_request)); } folly::coro::Task> co_lookupOneT( std::unique_ptr p_request) override { co_return doLookupOneT(std::move(p_request)); } folly::coro::Task> co_lookupManyT( std::unique_ptr p_request) override { co_return doLookupManyT(std::move(p_request)); } void async_eb_lookupOneE( std::unique_ptr>> callback, std::unique_ptr<::facebook::sbe::test::IOBuf> p_request) override { auto res = doLookupOne(std::move(p_request)); callback->complete(folly::Try{std::move(res)}); } void async_eb_lookupManyE( std::unique_ptr>> callback, std::unique_ptr<::facebook::sbe::test::IOBuf> p_request) override { auto res = doLookupMany(std::move(p_request)); callback->complete(folly::Try{std::move(res)}); } void async_eb_lookupOneTE( std::unique_ptr>> callback, std::unique_ptr<::facebook::sbe::test::TSingleCustomerLookup> p_request) override { auto res = doLookupOneT(std::move(p_request)); callback->complete(folly::Try{std::move(res)}); } void async_eb_lookupManyTE( std::unique_ptr>> callback, std::unique_ptr<::facebook::sbe::test::TMultipleCustomerLookup> p_request) override { auto res = doLookupManyT(std::move(p_request)); callback->complete(folly::Try{std::move(res)}); } folly::F14FastMap& getCustomers() { return customers_; } private: folly::F14FastMap customers_; std::unique_ptr customerNotFound_; std::unique_ptr doLookupOne(std::unique_ptr); std::unique_ptr doLookupMany(std::unique_ptr); std::unique_ptr doLookupOneT( std::unique_ptr); std::unique_ptr doLookupManyT( std::unique_ptr); size_t calculateCustomerReponseSize(const Customer& customer); inline void customerToCustomerResponse( apache::thrift::sbe::MessageWrapper& customerResponse, const Customer& customer); inline void customerToCustomerResponse( folly::IOBuf& buf, const Customer& customer); inline void customerToCustomerResponse( char* buffer, size_t length, const Customer& customer); inline std::unique_ptr customerToCustomerResponse( const Customer& customer); inline TCustomerResponse customerToTCustomerResponse( const Customer& customer); }; } // namespace facebook::sbe::test