From 077203fcf22bc2302dec2f62cc5cd313c61209d2 Mon Sep 17 00:00:00 2001 From: Oliver Kunz Date: Thu, 3 Mar 2022 04:47:46 -0800 Subject: [PATCH] Change to proto2::MessageLite and resolve reflextion for mobile builds PiperOrigin-RevId: 432164927 Change-Id: I0821cf443393b0bb16a68fc5750a9633a3f27725 --- sandboxed_api/client.cc | 7 ++++--- sandboxed_api/proto_helper.cc | 7 +++---- sandboxed_api/proto_helper.h | 6 +++--- sandboxed_api/sandbox2/comms.cc | 4 ++-- sandboxed_api/sandbox2/comms.h | 4 ++-- sandboxed_api/var_proto.h | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sandboxed_api/client.cc b/sandboxed_api/client.cc index db33424..25e28b3 100644 --- a/sandboxed_api/client.cc +++ b/sandboxed_api/client.cc @@ -143,7 +143,7 @@ class FunctionCallPreparer { private: // Deserializes the protobuf argument. - google::protobuf::Message** GetDeserializedProto(LenValStruct* src) { + google::protobuf::MessageLite** GetDeserializedProto(LenValStruct* src) { ProtoArg proto_arg; if (!proto_arg.ParseFromArray(src->data, src->size)) { LOG(FATAL) << "Unable to parse ProtoArg."; @@ -153,7 +153,7 @@ class FunctionCallPreparer { proto_arg.full_name()); LOG_IF(FATAL, desc == nullptr) << "Unable to find the descriptor for '" << proto_arg.full_name() << "'" << desc; - google::protobuf::Message* deserialized_proto = + google::protobuf::MessageLite* deserialized_proto = google::protobuf::MessageFactory::generated_factory()->GetPrototype(desc)->New(); LOG_IF(FATAL, deserialized_proto == nullptr) << "Unable to create deserialized proto for " << proto_arg.full_name(); @@ -168,7 +168,8 @@ class FunctionCallPreparer { // Use list instead of vector to preserve references even with modifications. // Contains pairs of lenval message pointer -> deserialized message // so that we can serialize the argument again after the function call. - std::list> protos_to_be_destroyed_; + std::list> + protos_to_be_destroyed_; ffi_type* ret_type_; ffi_type* arg_types_[FuncCall::kArgsMax]; const void* arg_values_[FuncCall::kArgsMax]; diff --git a/sandboxed_api/proto_helper.cc b/sandboxed_api/proto_helper.cc index 17f9132..21eb0d5 100644 --- a/sandboxed_api/proto_helper.cc +++ b/sandboxed_api/proto_helper.cc @@ -21,7 +21,7 @@ namespace sapi { namespace internal { absl::Status DeserializeProto(const char* data, size_t len, - google::protobuf::Message& output) { + google::protobuf::MessageLite& output) { ProtoArg envelope; if (!envelope.ParseFromArray(data, len)) { return absl::InternalError("Unable to parse proto from array"); @@ -37,13 +37,12 @@ absl::Status DeserializeProto(const char* data, size_t len, } // namespace internal absl::StatusOr> SerializeProto( - const google::protobuf::Message& proto) { + const google::protobuf::MessageLite& proto) { // Wrap protobuf in a envelope so that we know the name of the protobuf // structure when deserializing in the sandboxee. ProtoArg proto_arg; proto_arg.set_protobuf_data(proto.SerializeAsString()); - proto_arg.set_full_name(proto.GetDescriptor()->full_name()); - + proto_arg.set_full_name(proto.GetTypeName()); std::vector serialized_proto(proto_arg.ByteSizeLong()); if (!proto_arg.SerializeToArray(serialized_proto.data(), serialized_proto.size())) { diff --git a/sandboxed_api/proto_helper.h b/sandboxed_api/proto_helper.h index 3cc887c..23819d8 100644 --- a/sandboxed_api/proto_helper.h +++ b/sandboxed_api/proto_helper.h @@ -31,16 +31,16 @@ namespace sapi { namespace internal { absl::Status DeserializeProto(const char* data, size_t len, - google::protobuf::Message& output); + google::protobuf::MessageLite& output); } // namespace internal absl::StatusOr> SerializeProto( - const google::protobuf::Message& proto); + const google::protobuf::MessageLite& proto); template absl::StatusOr DeserializeProto(const char* data, size_t len) { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of::value, "Template argument must be a proto message"); T result; SAPI_RETURN_IF_ERROR( diff --git a/sandboxed_api/sandbox2/comms.cc b/sandboxed_api/sandbox2/comms.cc index 9b27e0d..0450c1e 100644 --- a/sandboxed_api/sandbox2/comms.cc +++ b/sandboxed_api/sandbox2/comms.cc @@ -437,7 +437,7 @@ bool Comms::SendFD(int fd) { return true; } -bool Comms::RecvProtoBuf(google::protobuf::Message* message) { +bool Comms::RecvProtoBuf(google::protobuf::MessageLite* message) { uint32_t tag; std::vector bytes; if (!RecvTLV(&tag, &bytes)) { @@ -457,7 +457,7 @@ bool Comms::RecvProtoBuf(google::protobuf::Message* message) { return message->ParseFromArray(bytes.data(), bytes.size()); } -bool Comms::SendProtoBuf(const google::protobuf::Message& message) { +bool Comms::SendProtoBuf(const google::protobuf::MessageLite& message) { std::string str; if (!message.SerializeToString(&str)) { SAPI_RAW_LOG(ERROR, "Couldn't serialize the ProtoBuf"); diff --git a/sandboxed_api/sandbox2/comms.h b/sandboxed_api/sandbox2/comms.h index 22be306..1d9a20a 100644 --- a/sandboxed_api/sandbox2/comms.h +++ b/sandboxed_api/sandbox2/comms.h @@ -155,8 +155,8 @@ class Comms { bool SendFD(int fd); // Receives/sends protobufs. - bool RecvProtoBuf(google::protobuf::Message* message); - bool SendProtoBuf(const google::protobuf::Message& message); + bool RecvProtoBuf(google::protobuf::MessageLite* message); + bool SendProtoBuf(const google::protobuf::MessageLite& message); // Receives/sends Status objects. bool RecvStatus(absl::Status* status); diff --git a/sandboxed_api/var_proto.h b/sandboxed_api/var_proto.h index 3228126..b45647a 100644 --- a/sandboxed_api/var_proto.h +++ b/sandboxed_api/var_proto.h @@ -35,7 +35,7 @@ namespace sapi::v { template class Proto : public Var { public: - static_assert(std::is_base_of::value, + static_assert(std::is_base_of::value, "Template argument must be a proto message"); ABSL_DEPRECATED("Use Proto<>::FromMessage() instead")