diff --git a/third-party/thrift/src/thrift/lib/cpp2/op/detail/StructPatch.h b/third-party/thrift/src/thrift/lib/cpp2/op/detail/StructPatch.h index 79a86b3bb3fd4a..b7a78d0dfc5651 100644 --- a/third-party/thrift/src/thrift/lib/cpp2/op/detail/StructPatch.h +++ b/third-party/thrift/src/thrift/lib/cpp2/op/detail/StructPatch.h @@ -367,6 +367,12 @@ class BaseEnsurePatch : public BaseClearPatch { } } } + template + std::enable_if_t> ensure( + const std::unique_ptr& defaultVal) { + ensure(std::make_unique(*defaultVal)); + } + /// Ensures the given field is initalized, and return the associated patch /// object. template diff --git a/third-party/thrift/src/thrift/lib/cpp2/op/detail/ValuePatch.h b/third-party/thrift/src/thrift/lib/cpp2/op/detail/ValuePatch.h index 6ddf14c7cd8f55..f6d9313c828427 100644 --- a/third-party/thrift/src/thrift/lib/cpp2/op/detail/ValuePatch.h +++ b/third-party/thrift/src/thrift/lib/cpp2/op/detail/ValuePatch.h @@ -375,6 +375,8 @@ class BinaryPatch : public BaseStringPatch> { void assign(std::string s) { assign(*folly::IOBuf::fromString(std::move(s))); } + void assign(std::unique_ptr&& s) { assign(std::move(*s)); } + void assign(const std::unique_ptr& s) { assign(*s); } template BinaryPatch& operator=(T&& other) { @@ -427,6 +429,13 @@ class BinaryPatch : public BaseStringPatch> { val = buf->toString(); } + void apply(std::unique_ptr& val) const { + if (!val) { + val = std::make_unique(); + } + apply(*val); + } + private: using Base::assignOr; using Base::data_;