1 // This file is part of CAF, the C++ Actor Framework. See the file LICENSE in 2 // the main distribution directory for license terms and copyright or visit 3 // https://github.com/actor-framework/actor-framework/blob/master/LICENSE. 4 5 #pragma once 6 7 #include <cstddef> 8 #include <string> 9 #include <utility> 10 11 #include "caf/config.hpp" 12 13 namespace caf::io { 14 15 enum class receive_policy_flag : unsigned { at_least, at_most, exactly }; 16 to_integer(receive_policy_flag x)17constexpr unsigned to_integer(receive_policy_flag x) { 18 return static_cast<unsigned>(x); 19 } 20 to_string(receive_policy_flag x)21inline std::string to_string(receive_policy_flag x) { 22 return x == receive_policy_flag::at_least 23 ? "at_least" 24 : (x == receive_policy_flag::at_most ? "at_most" : "exactly"); 25 } 26 27 class receive_policy { 28 public: 29 receive_policy() = delete; 30 31 using config = std::pair<receive_policy_flag, size_t>; 32 at_least(size_t num_bytes)33 static config at_least(size_t num_bytes) { 34 CAF_ASSERT(num_bytes > 0); 35 return {receive_policy_flag::at_least, num_bytes}; 36 } 37 at_most(size_t num_bytes)38 static config at_most(size_t num_bytes) { 39 CAF_ASSERT(num_bytes > 0); 40 return {receive_policy_flag::at_most, num_bytes}; 41 } 42 exactly(size_t num_bytes)43 static config exactly(size_t num_bytes) { 44 CAF_ASSERT(num_bytes > 0); 45 return {receive_policy_flag::exactly, num_bytes}; 46 } 47 }; 48 49 } // namespace caf::io 50