dep-protobuf/rust/cpp_kernel/message.cc
Adam Cozzette 7f395af40e Replace some per-message C++ thunks with a common implementation
This change adds delete, clear, serialize, parse, copy_from, and merge_from
operations to the runtime. Since these operations can all be implemented easily
on the `MessageLite` interface, we can use a common implementation in the
runtime instead of generating per-message thunks for all of these.

I suspect this will also make it possible to remove some of our generated trait
implementations and replace them with blanket implementations, but I will leave
that for a future change.

PiperOrigin-RevId: 665910927
2024-08-21 09:34:25 -07:00

36 lines
1.2 KiB
C++

#include <limits>
#include "google/protobuf/message_lite.h"
#include "rust/cpp_kernel/serialized_data.h"
extern "C" {
void proto2_rust_Message_delete(google::protobuf::MessageLite* m) { delete m; }
void proto2_rust_Message_clear(google::protobuf::MessageLite* m) { m->Clear(); }
bool proto2_rust_Message_parse(google::protobuf::MessageLite* m,
google::protobuf::rust::SerializedData input) {
if (input.len > std::numeric_limits<int>::max()) {
return false;
}
return m->ParseFromArray(input.data, static_cast<int>(input.len));
}
bool proto2_rust_Message_serialize(const google::protobuf::MessageLite* m,
google::protobuf::rust::SerializedData* output) {
return google::protobuf::rust::SerializeMsg(m, output);
}
void proto2_rust_Message_copy_from(google::protobuf::MessageLite* dst,
const google::protobuf::MessageLite& src) {
dst->Clear();
dst->CheckTypeAndMergeFrom(src);
}
void proto2_rust_Message_merge_from(google::protobuf::MessageLite* dst,
const google::protobuf::MessageLite& src) {
dst->CheckTypeAndMergeFrom(src);
}
} // extern "C"