Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/common/include/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,5 @@ class Attributes {

// Kinds are contained at the context level, not inside attributes.
};

} // namespace launchdarkly
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace launchdarkly {
* For more information, see the [SDK reference guide]
* (https://docs.launchdarkly.com/sdk/features/evaluation-reasons#TODO).
*/
class EvaluationDetail {
class EvaluationDetailInternal {
public:
/**
* The result of the flag evaluation. This will be either one of the flag's
Expand All @@ -41,7 +41,7 @@ class EvaluationDetail {
[[nodiscard]] std::optional<std::reference_wrapper<EvaluationReason const>>
reason() const;

EvaluationDetail(Value value,
EvaluationDetailInternal(Value value,
std::optional<std::size_t> variation_index,
std::optional<EvaluationReason> reason);

Expand Down
11 changes: 0 additions & 11 deletions libs/common/include/data/evaluation_reason.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <optional>
#include <string>

#include <boost/json/value.hpp>

namespace launchdarkly {

/**
Expand Down Expand Up @@ -97,13 +95,4 @@ class EvaluationReason {
std::optional<std::string> big_segment_status_;
};

/**
* Method used by boost::json for converting a boost::json::value into a
* launchdarkly::EvaluationReason.
* @return A EvaluationReason representation of the boost::json::value.
*/
EvaluationReason tag_invoke(
boost::json::value_to_tag<EvaluationReason> const& unused,
boost::json::value const& json_value);

} // namespace launchdarkly
19 changes: 4 additions & 15 deletions libs/common/include/data/evaluation_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include <chrono>
#include <optional>

#include <boost/json/value.hpp>

#include "evaluation_detail.hpp"
#include "evaluation_detail_internal.hpp"

namespace launchdarkly {

Expand Down Expand Up @@ -47,7 +45,7 @@ class EvaluationResult {
/**
* Details of the flags evaluation.
*/
[[nodiscard]] EvaluationDetail const& detail() const;
[[nodiscard]] EvaluationDetailInternal const& detail() const;

EvaluationResult(
uint64_t version,
Expand All @@ -56,7 +54,7 @@ class EvaluationResult {
bool track_reason,
std::optional<std::chrono::time_point<std::chrono::system_clock>>
debug_events_until_date,
EvaluationDetail detail);
EvaluationDetailInternal detail);

private:
uint64_t version_;
Expand All @@ -65,16 +63,7 @@ class EvaluationResult {
bool track_reason_;
std::optional<std::chrono::time_point<std::chrono::system_clock>>
debug_events_until_date_;
EvaluationDetail detail_;
EvaluationDetailInternal detail_;
};

/**
* Method used by boost::json for converting a boost::json::value into a
* launchdarkly::EvaluationResult.
* @return A EvaluationResult representation of the boost::json::value.
*/
EvaluationResult tag_invoke(
boost::json::value_to_tag<EvaluationResult> const& unused,
boost::json::value const& json_value);

} // namespace launchdarkly
14 changes: 14 additions & 0 deletions libs/common/include/serialization/json_attributes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefixed json. Maybe we would want protobuf or binary or some other thing in the future. /shrug


#include <boost/json.hpp>
#include "attributes.hpp"

namespace launchdarkly {
/**
* Method used by boost::json for converting launchdarkly::Attributes into a
* boost::json::value.
*/
void tag_invoke(boost::json::value_from_tag const&,
boost::json::value& json_value,
Attributes const& attributes);
} // namespace launchdarkly
15 changes: 15 additions & 0 deletions libs/common/include/serialization/json_context.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <boost/json.hpp>

#include "context.hpp"

namespace launchdarkly {
/**
* Method used by boost::json for converting a launchdarkly::Context into a
* boost::json::value.
*/
void tag_invoke(boost::json::value_from_tag const&,
boost::json::value& json_value,
Context const& ld_context);
} // namespace launchdarkly
16 changes: 16 additions & 0 deletions libs/common/include/serialization/json_evaluation_reason.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <boost/json.hpp>

#include "data/evaluation_reason.hpp"

namespace launchdarkly {
/**
* Method used by boost::json for converting a boost::json::value into a
* launchdarkly::EvaluationReason.
* @return A EvaluationReason representation of the boost::json::value.
*/
EvaluationReason tag_invoke(
boost::json::value_to_tag<EvaluationReason> const& unused,
boost::json::value const& json_value);
} // namespace launchdarkly
16 changes: 16 additions & 0 deletions libs/common/include/serialization/json_evaluation_result.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <boost/json.hpp>

#include "data/evaluation_result.hpp"

namespace launchdarkly {
/**
* Method used by boost::json for converting a boost::json::value into a
* launchdarkly::EvaluationResult.
* @return A EvaluationResult representation of the boost::json::value.
*/
EvaluationResult tag_invoke(
boost::json::value_to_tag<EvaluationResult> const& unused,
boost::json::value const& json_value);
} // namespace launchdarkly
23 changes: 23 additions & 0 deletions libs/common/include/serialization/json_value.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <boost/json.hpp>

#include "value.hpp"

namespace launchdarkly {
/**
* Method used by boost::json for converting a boost::json::value into a
* launchdarkly::Value.
* @return A Value representation of the boost::json::value.
*/
Value tag_invoke(boost::json::value_to_tag<Value> const&,
boost::json::value const&);

/**
* Method used by boost::json for converting a launchdarkly::Value into a
* boost::json::value.
*/
void tag_invoke(boost::json::value_from_tag const&,
boost::json::value& json_value,
Value const& ld_value);
} // namespace launchdarkly
9 changes: 0 additions & 9 deletions libs/common/include/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <string>
#include <vector>

#include <boost/json/value.hpp>
#include <boost/variant.hpp>

namespace launchdarkly {
Expand Down Expand Up @@ -425,12 +424,4 @@ class Value {
static const Value null_value_;
};

/**
* Method used by boost::json for converting a boost::json::value into a
* launchdarkly::Value.
* @return A Value representation of the boost::json::value.
*/
Value tag_invoke(boost::json::value_to_tag<Value> const&,
boost::json::value const&);

} // namespace launchdarkly
9 changes: 7 additions & 2 deletions libs/common/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ add_library(${LIBNAME}
config/config_builder.cpp
config/config.cpp
data/evaluation_reason.cpp
data/evaluation_detail.cpp
data/evaluation_detail_internal.cpp
data/evaluation_result.cpp
context_filter.cpp
config/application_info.cpp
lib.cpp
value_mapping.cpp)
value_mapping.cpp
serialization/json_attributes.cpp
serialization/json_context.cpp
serialization/json_evaluation_reason.cpp
serialization/json_evaluation_result.cpp
serialization/json_value.cpp)


add_library(launchdarkly::common ALIAS ${LIBNAME})
Expand Down
24 changes: 0 additions & 24 deletions libs/common/src/data/evaluation_detail.cpp

This file was deleted.

25 changes: 25 additions & 0 deletions libs/common/src/data/evaluation_detail_internal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "data/evaluation_detail_internal.hpp"

namespace launchdarkly {

Value const& EvaluationDetailInternal::value() const {
return value_;
}

std::optional<std::size_t> EvaluationDetailInternal::variation_index() const {
return variation_index_;
}

std::optional<std::reference_wrapper<EvaluationReason const>>
EvaluationDetailInternal::reason() const {
return reason_;
}
EvaluationDetailInternal::EvaluationDetailInternal(
Value value,
std::optional<std::size_t> variation_index,
std::optional<EvaluationReason> reason)
: value_(std::move(value)),
variation_index_(variation_index),
reason_(std::move(reason)) {}

} // namespace launchdarkly
40 changes: 0 additions & 40 deletions libs/common/src/data/evaluation_reason.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "data/evaluation_reason.hpp"
#include "value_mapping.hpp"

namespace launchdarkly {

Expand Down Expand Up @@ -47,43 +46,4 @@ EvaluationReason::EvaluationReason(
in_experiment_(in_experiment),
big_segment_status_(std::move(big_segment_status)) {}

EvaluationReason tag_invoke(
boost::json::value_to_tag<EvaluationReason> const& unused,
boost::json::value const& json_value) {
boost::ignore_unused(unused);
if (json_value.is_object()) {
auto json_obj = json_value.as_object();

auto* kind_iter = json_obj.find("kind");
auto kind =
ValueOrDefault<std::string>(kind_iter, json_obj.end(), "ERROR");

auto* error_kind_iter = json_obj.find("errorKind");
auto error_kind =
ValueAsOpt<std::string>(error_kind_iter, json_obj.end());

auto* rule_index_iter = json_obj.find("ruleIndex");
auto rule_index = ValueAsOpt<uint64_t>(rule_index_iter, json_obj.end());

auto* rule_id_iter = json_obj.find("ruleId");
auto rule_id = ValueAsOpt<std::string>(rule_id_iter, json_obj.end());

auto* prerequisite_key_iter = json_obj.find("prerequisiteKey");
auto prerequisite_key =
ValueAsOpt<std::string>(prerequisite_key_iter, json_obj.end());

auto* in_experiment_iter = json_obj.find("inExperiment");
auto in_experiment =
ValueOrDefault(in_experiment_iter, json_obj.end(), false);

auto* big_segment_status_iter = json_obj.find("bigSegmentStatus");
auto big_segment_status =
ValueAsOpt<std::string>(big_segment_status_iter, json_obj.end());

return {std::string(kind), error_kind, rule_index, rule_id,
prerequisite_key, in_experiment, big_segment_status};
}
return {"ERROR", std::nullopt, 0, std::nullopt,
std::nullopt, false, std::nullopt};
}
} // namespace launchdarkly
Loading