C++ Server-Side SDK
LaunchDarkly SDK
fdv2_source_result.hpp
1 #pragma once
2 
3 #include "../item_change.hpp"
4 
5 #include <launchdarkly/data_model/change_set.hpp>
6 #include <launchdarkly/data_sources/data_source_status_error_info.hpp>
7 
8 #include <charconv>
9 #include <chrono>
10 #include <cstdint>
11 #include <optional>
12 #include <string>
13 #include <string_view>
14 #include <system_error>
15 #include <variant>
16 
17 namespace launchdarkly::server_side::data_interfaces {
18 
26  static constexpr std::chrono::seconds kDefaultTtl = std::chrono::hours(1);
27 
33  static std::optional<std::chrono::seconds> ParseTtl(
34  std::string_view value) {
35  std::uint64_t seconds = 0;
36  auto const* begin = value.data();
37  auto const* end = begin + value.size();
38  auto const [ptr, ec] = std::from_chars(begin, end, seconds);
39  if (ec != std::errc{} || ptr != end) {
40  return std::nullopt;
41  }
42  return std::chrono::seconds(seconds);
43  }
44 
50  std::chrono::seconds ttl = kDefaultTtl;
51 };
52 
58 
62  struct ChangeSet {
63  data_model::ChangeSet<ChangeSetData> change_set;
64  };
65 
69  struct Interrupted {
70  ErrorInfo error;
71  };
72 
76  struct TerminalError {
77  ErrorInfo error;
78  };
79 
83  struct Shutdown {};
84 
88  struct Goodbye {
89  std::optional<std::string> reason;
90  };
91 
92  using Value =
93  std::variant<ChangeSet, Interrupted, TerminalError, Shutdown, Goodbye>;
94 
95  Value value;
96 
100  std::optional<FDv1FallbackDirective> fdv1_fallback;
101 };
102 
103 } // namespace launchdarkly::server_side::data_interfaces
Definition: data_source_status_error_info.hpp:14
static std::optional< std::chrono::seconds > ParseTtl(std::string_view value)
Definition: fdv2_source_result.hpp:33
std::chrono::seconds ttl
Definition: fdv2_source_result.hpp:50
static constexpr std::chrono::seconds kDefaultTtl
Definition: fdv2_source_result.hpp:26
std::optional< FDv1FallbackDirective > fdv1_fallback
Definition: fdv2_source_result.hpp:100