proxygen
Negotiator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <folly/Optional.h>
12 
13 namespace fizz {
14 namespace server {
15 
21 template <typename T>
23  const std::vector<std::vector<T>>& serverPref,
24  const std::vector<T>& clientPref) {
25  for (const auto& prefTier : serverPref) {
26  if (prefTier.size() == 1) {
27  if (std::find(clientPref.begin(), clientPref.end(), prefTier.front()) !=
28  clientPref.end()) {
29  return prefTier.front();
30  }
31  } else {
32  for (const auto& pref : clientPref) {
33  if (std::find(prefTier.begin(), prefTier.end(), pref) !=
34  prefTier.end()) {
35  return pref;
36  }
37  }
38  }
39  }
40  return folly::none;
41 }
42 
47 template <typename T>
49  const std::vector<T>& serverPref,
50  const std::vector<T>& clientPref) {
51  for (const auto& pref : serverPref) {
52  if (std::find(clientPref.begin(), clientPref.end(), pref) !=
53  clientPref.end()) {
54  return pref;
55  }
56  }
57  return folly::none;
58 }
59 } // namespace server
60 } // namespace fizz
folly::Optional< T > negotiate(const std::vector< std::vector< T >> &serverPref, const std::vector< T > &clientPref)
Definition: Negotiator.h:22
Definition: Actions.h:16
constexpr None none
Definition: Optional.h:87