mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Fix sapi:✌️:Proto<T>::FromMessage
PiperOrigin-RevId: 611076146 Change-Id: I60edf17b83e0ded8ed62aeebba45b6401bac8e53
This commit is contained in:
parent
f7f4cdb458
commit
e7c5de0db8
@ -42,16 +42,26 @@ namespace sapi::v {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class Proto : public Var {
|
class Proto : public Var {
|
||||||
public:
|
public:
|
||||||
|
class PrivateToken {
|
||||||
|
private:
|
||||||
|
explicit PrivateToken() = default;
|
||||||
|
friend class Proto;
|
||||||
|
};
|
||||||
|
|
||||||
static_assert(std::is_base_of<google::protobuf::MessageLite, T>::value,
|
static_assert(std::is_base_of<google::protobuf::MessageLite, T>::value,
|
||||||
"Template argument must be a proto message");
|
"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")
|
ABSL_DEPRECATED("Use Proto<>::FromMessage() instead")
|
||||||
explicit Proto(const T& proto)
|
explicit Proto(const T& proto)
|
||||||
: wrapped_var_(SerializeProto(proto).value()) {}
|
: wrapped_var_(SerializeProto(proto).value()) {}
|
||||||
|
|
||||||
static absl::StatusOr<Proto<T>> FromMessage(const T& proto) {
|
static absl::StatusOr<Proto<T>> FromMessage(const T& proto) {
|
||||||
SAPI_ASSIGN_OR_RETURN(std::vector<uint8_t> len_val, SerializeProto(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(); }
|
size_t GetSize() const final { return wrapped_var_.GetSize(); }
|
||||||
@ -105,10 +115,6 @@ class Proto : public Var {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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 management of reading/writing the data to the sandboxee is handled by
|
||||||
// the LenVal class.
|
// the LenVal class.
|
||||||
LenVal wrapped_var_;
|
LenVal wrapped_var_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user