Change to proto2::MessageLite and resolve reflextion for mobile builds

PiperOrigin-RevId: 432164927
Change-Id: I0821cf443393b0bb16a68fc5750a9633a3f27725
This commit is contained in:
Oliver Kunz 2022-03-03 04:47:46 -08:00 committed by Copybara-Service
parent e1a9513783
commit 077203fcf2
6 changed files with 15 additions and 15 deletions

View File

@ -143,7 +143,7 @@ class FunctionCallPreparer {
private: private:
// Deserializes the protobuf argument. // Deserializes the protobuf argument.
google::protobuf::Message** GetDeserializedProto(LenValStruct* src) { google::protobuf::MessageLite** GetDeserializedProto(LenValStruct* src) {
ProtoArg proto_arg; ProtoArg proto_arg;
if (!proto_arg.ParseFromArray(src->data, src->size)) { if (!proto_arg.ParseFromArray(src->data, src->size)) {
LOG(FATAL) << "Unable to parse ProtoArg."; LOG(FATAL) << "Unable to parse ProtoArg.";
@ -153,7 +153,7 @@ class FunctionCallPreparer {
proto_arg.full_name()); proto_arg.full_name());
LOG_IF(FATAL, desc == nullptr) << "Unable to find the descriptor for '" LOG_IF(FATAL, desc == nullptr) << "Unable to find the descriptor for '"
<< proto_arg.full_name() << "'" << desc; << proto_arg.full_name() << "'" << desc;
google::protobuf::Message* deserialized_proto = google::protobuf::MessageLite* deserialized_proto =
google::protobuf::MessageFactory::generated_factory()->GetPrototype(desc)->New(); google::protobuf::MessageFactory::generated_factory()->GetPrototype(desc)->New();
LOG_IF(FATAL, deserialized_proto == nullptr) LOG_IF(FATAL, deserialized_proto == nullptr)
<< "Unable to create deserialized proto for " << proto_arg.full_name(); << "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. // Use list instead of vector to preserve references even with modifications.
// Contains pairs of lenval message pointer -> deserialized message // Contains pairs of lenval message pointer -> deserialized message
// so that we can serialize the argument again after the function call. // so that we can serialize the argument again after the function call.
std::list<std::pair<LenValStruct*, google::protobuf::Message*>> protos_to_be_destroyed_; std::list<std::pair<LenValStruct*, google::protobuf::MessageLite*>>
protos_to_be_destroyed_;
ffi_type* ret_type_; ffi_type* ret_type_;
ffi_type* arg_types_[FuncCall::kArgsMax]; ffi_type* arg_types_[FuncCall::kArgsMax];
const void* arg_values_[FuncCall::kArgsMax]; const void* arg_values_[FuncCall::kArgsMax];

View File

@ -21,7 +21,7 @@ namespace sapi {
namespace internal { namespace internal {
absl::Status DeserializeProto(const char* data, size_t len, absl::Status DeserializeProto(const char* data, size_t len,
google::protobuf::Message& output) { google::protobuf::MessageLite& output) {
ProtoArg envelope; ProtoArg envelope;
if (!envelope.ParseFromArray(data, len)) { if (!envelope.ParseFromArray(data, len)) {
return absl::InternalError("Unable to parse proto from array"); return absl::InternalError("Unable to parse proto from array");
@ -37,13 +37,12 @@ absl::Status DeserializeProto(const char* data, size_t len,
} // namespace internal } // namespace internal
absl::StatusOr<std::vector<uint8_t>> SerializeProto( absl::StatusOr<std::vector<uint8_t>> 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 // Wrap protobuf in a envelope so that we know the name of the protobuf
// structure when deserializing in the sandboxee. // structure when deserializing in the sandboxee.
ProtoArg proto_arg; ProtoArg proto_arg;
proto_arg.set_protobuf_data(proto.SerializeAsString()); 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<uint8_t> serialized_proto(proto_arg.ByteSizeLong()); std::vector<uint8_t> serialized_proto(proto_arg.ByteSizeLong());
if (!proto_arg.SerializeToArray(serialized_proto.data(), if (!proto_arg.SerializeToArray(serialized_proto.data(),
serialized_proto.size())) { serialized_proto.size())) {

View File

@ -31,16 +31,16 @@ namespace sapi {
namespace internal { namespace internal {
absl::Status DeserializeProto(const char* data, size_t len, absl::Status DeserializeProto(const char* data, size_t len,
google::protobuf::Message& output); google::protobuf::MessageLite& output);
} // namespace internal } // namespace internal
absl::StatusOr<std::vector<uint8_t>> SerializeProto( absl::StatusOr<std::vector<uint8_t>> SerializeProto(
const google::protobuf::Message& proto); const google::protobuf::MessageLite& proto);
template <typename T> template <typename T>
absl::StatusOr<T> DeserializeProto(const char* data, size_t len) { absl::StatusOr<T> DeserializeProto(const char* data, size_t len) {
static_assert(std::is_base_of<google::protobuf::Message, 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");
T result; T result;
SAPI_RETURN_IF_ERROR( SAPI_RETURN_IF_ERROR(

View File

@ -437,7 +437,7 @@ bool Comms::SendFD(int fd) {
return true; return true;
} }
bool Comms::RecvProtoBuf(google::protobuf::Message* message) { bool Comms::RecvProtoBuf(google::protobuf::MessageLite* message) {
uint32_t tag; uint32_t tag;
std::vector<uint8_t> bytes; std::vector<uint8_t> bytes;
if (!RecvTLV(&tag, &bytes)) { if (!RecvTLV(&tag, &bytes)) {
@ -457,7 +457,7 @@ bool Comms::RecvProtoBuf(google::protobuf::Message* message) {
return message->ParseFromArray(bytes.data(), bytes.size()); 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; std::string str;
if (!message.SerializeToString(&str)) { if (!message.SerializeToString(&str)) {
SAPI_RAW_LOG(ERROR, "Couldn't serialize the ProtoBuf"); SAPI_RAW_LOG(ERROR, "Couldn't serialize the ProtoBuf");

View File

@ -155,8 +155,8 @@ class Comms {
bool SendFD(int fd); bool SendFD(int fd);
// Receives/sends protobufs. // Receives/sends protobufs.
bool RecvProtoBuf(google::protobuf::Message* message); bool RecvProtoBuf(google::protobuf::MessageLite* message);
bool SendProtoBuf(const google::protobuf::Message& message); bool SendProtoBuf(const google::protobuf::MessageLite& message);
// Receives/sends Status objects. // Receives/sends Status objects.
bool RecvStatus(absl::Status* status); bool RecvStatus(absl::Status* status);

View File

@ -35,7 +35,7 @@ namespace sapi::v {
template <typename T> template <typename T>
class Proto : public Var { class Proto : public Var {
public: public:
static_assert(std::is_base_of<google::protobuf::Message, 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");
ABSL_DEPRECATED("Use Proto<>::FromMessage() instead") ABSL_DEPRECATED("Use Proto<>::FromMessage() instead")