Fix sapi:✌️:Proto<T>::FromMessage

PiperOrigin-RevId: 611076146
Change-Id: I60edf17b83e0ded8ed62aeebba45b6401bac8e53
This commit is contained in:
Wiktor Garbacz 2024-02-28 06:00:44 -08:00 committed by Copybara-Service
parent f7f4cdb458
commit e7c5de0db8

View File

@ -42,16 +42,26 @@ namespace sapi::v {
template <typename T>
class Proto : public Var {
public:
class PrivateToken {
private:
explicit PrivateToken() = default;
friend class Proto;
};
static_assert(std::is_base_of<google::protobuf::MessageLite, T>::value,
"Template argument must be a proto message");
Proto(PrivateToken, std::vector<uint8_t> data)
: wrapped_var_(std::move(data)) {}
ABSL_DEPRECATED("Use Proto<>::FromMessage() instead")
explicit Proto(const T& proto)
: wrapped_var_(SerializeProto(proto).value()) {}
static absl::StatusOr<Proto<T>> FromMessage(const T& proto) {
SAPI_ASSIGN_OR_RETURN(std::vector<uint8_t> len_val, SerializeProto(proto));
return absl::StatusOr<Proto<T>>(absl::in_place, proto);
return absl::StatusOr<Proto<T>>(absl::in_place, PrivateToken{},
std::move(len_val));
}
size_t GetSize() const final { return wrapped_var_.GetSize(); }
@ -105,10 +115,6 @@ class Proto : public Var {
}
private:
friend class absl::StatusOr<Proto<T>>;
explicit Proto(std::vector<uint8_t> data) : wrapped_var_(std::move(data)) {}
// The management of reading/writing the data to the sandboxee is handled by
// the LenVal class.
LenVal wrapped_var_;