Skip to content

Commit

Permalink
Implement AssignPatch::toSafePatch
Browse files Browse the repository at this point in the history
Reviewed By: pranavtbhat

Differential Revision: D66671131

fbshipit-source-id: 3216c9f05988c0f92d7462eed90efdcccb523afd
  • Loading branch information
TJ Yin authored and facebook-github-bot committed Dec 5, 2024
1 parent 0207ecf commit 34372c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 12 additions & 1 deletion third-party/thrift/src/thrift/lib/cpp2/op/AssignPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <folly/json.h>
#include <folly/logging/xlog.h>
#include <thrift/lib/cpp2/op/detail/BasePatch.h>
#include <thrift/lib/cpp2/op/Patch.h>
#include <thrift/lib/cpp2/protocol/Patch.h>

namespace apache::thrift {
Expand Down Expand Up @@ -138,6 +138,17 @@ class AssignPatch : public BaseAssignPatch<Patch, AssignPatch<Patch>> {
Base::reset();
}

template <class..., bool IsStructured = is_thrift_class_v<T>>
static auto fromSafePatch(
const typename std::enable_if_t<IsStructured, SafePatchType<Tag>>::type&
safePatch) {
return fromSafePatchImpl<AssignPatch>(safePatch);
}

auto toSafePatch() const {
return toSafePatchImpl<typename SafePatchType<Tag>::type>(*this);
}

private:
using Base::data_;
std::optional<protocol::Object> dynPatch_;
Expand Down
14 changes: 11 additions & 3 deletions third-party/thrift/src/thrift/lib/cpp2/op/detail/PatchTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ template <class>
constexpr inline bool is_any_patch_v = false;
template <class Patch>
constexpr inline bool is_any_patch_v<AnyPatch<Patch>> = true;
template <class>
constexpr inline bool is_assign_patch_v = false;
template <class Patch>
constexpr inline bool is_assign_patch_v<AssignPatch<Patch>> = true;

class MinSafePatchVersionVisitor {
public:
Expand Down Expand Up @@ -170,9 +174,13 @@ class MinSafePatchVersionVisitor {
template <typename Patch>
int32_t calculateMinSafePatchVersion(const Patch& patch) {
// is_patch_v
MinSafePatchVersionVisitor visitor;
patch.customVisit(visitor);
return visitor.version;
if constexpr (is_assign_patch_v<Patch>) {
return 1;
} else {
MinSafePatchVersionVisitor visitor;
patch.customVisit(visitor);
return visitor.version;
}
}

} // namespace apache::thrift::op::detail

0 comments on commit 34372c8

Please sign in to comment.