Set up for Rust-cpp Protobuf implementation message matcher.

PiperOrigin-RevId: 658397591
pull/17656/head
Yamil Morales 6 months ago committed by Copybara-Service
parent c75787c327
commit 582e80eb8a
  1. 13
      rust/cpp.rs
  2. 3
      rust/cpp_kernel/BUILD
  3. 26
      rust/cpp_kernel/compare.cc
  4. 13
      rust/cpp_kernel/compare.h

@ -319,6 +319,19 @@ pub fn debug_string(_private: Private, msg: RawMessage, f: &mut fmt::Formatter<'
write!(f, "{dbg_str}")
}
extern "C" {
/// # Safety
/// - `msg1` and `msg2` legally dereferencable MessageLite* pointers.
fn proto2_rust_messagelite_equals(msg1: RawMessage, msg2: RawMessage) -> bool;
}
/// # Safety
/// - `msg1` and `msg2` legally dereferencable MessageLite* pointers.
pub unsafe fn raw_message_equals(_private: Private, msg1: RawMessage, msg2: RawMessage) -> bool {
// SAFETY: Same constraints placed on caller.
unsafe { proto2_rust_messagelite_equals(msg1, msg2) }
}
pub type RawMapIter = UntypedMapIterator;
/// The raw contents of every generated message.

@ -5,12 +5,14 @@ load("@rules_rust//rust:defs.bzl", "rust_library")
cc_library(
name = "cpp_api",
srcs = [
"compare.cc",
"debug.cc",
"map.cc",
"repeated.cc",
"strings.cc",
],
hdrs = [
"compare.h",
"debug.h",
"map.h",
"rust_alloc_for_cpp_api.h",
@ -25,6 +27,7 @@ cc_library(
":rust_alloc_for_cpp_api", # buildcleaner: keep
"//src/google/protobuf",
"//src/google/protobuf:protobuf_lite",
"//src/google/protobuf/io",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/strings:string_view",

@ -0,0 +1,26 @@
#include "rust/cpp_kernel/compare.h"
#include <string>
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
#include "google/protobuf/message_lite.h"
static std::string SerializeDeterministically(const google::protobuf::MessageLite& m) {
std::string serialized;
{
google::protobuf::io::StringOutputStream output_stream(&serialized);
google::protobuf::io::CodedOutputStream coded_stream(&output_stream);
coded_stream.SetSerializationDeterministic(true);
m.SerializePartialToCodedStream(&coded_stream);
}
return serialized;
}
extern "C" {
bool proto2_rust_messagelite_equals(const google::protobuf::MessageLite* msg1,
const google::protobuf::MessageLite* msg2) {
return SerializeDeterministically(*msg1) == SerializeDeterministically(*msg2);
}
} // extern "C"

@ -0,0 +1,13 @@
#ifndef GOOGLE_PROTOBUF_RUST_CPP_KERNEL_COMPARE_H__
#define GOOGLE_PROTOBUF_RUST_CPP_KERNEL_COMPARE_H__
#include "google/protobuf/message_lite.h"
extern "C" {
bool proto2_rust_messagelite_equals(const google::protobuf::MessageLite* msg1,
const google::protobuf::MessageLite* msg2);
} // extern "C"
#endif // GOOGLE_PROTOBUF_RUST_CPP_KERNEL_COMPARE_H__
Loading…
Cancel
Save