Skip to content

Commit

Permalink
Fix sapi::v::Proto<T>::FromMessage
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 611076146
Change-Id: I60edf17b83e0ded8ed62aeebba45b6401bac8e53
  • Loading branch information
happyCoder92 authored and copybara-github committed Feb 28, 2024
1 parent f7f4cdb commit e7c5de0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions sandboxed_api/var_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down Expand Up @@ -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_;
Expand Down

0 comments on commit e7c5de0

Please sign in to comment.