mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
Putting it into BUILD files unintentionally forces it on all our downstream users. Instead, we just want to enable this during testing and let them choose for themselves in their builds. Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing. Closed #14714 PiperOrigin-RevId: 666903224
38 lines
913 B
C++
38 lines
913 B
C++
#include "rust/cpp_kernel/strings.h"
|
|
|
|
#include <cstring>
|
|
#include <string>
|
|
|
|
#include "rust/cpp_kernel/rust_alloc_for_cpp_api.h"
|
|
|
|
namespace google {
|
|
namespace protobuf {
|
|
namespace rust {
|
|
|
|
RustStringRawParts::RustStringRawParts(std::string src) {
|
|
if (src.empty()) {
|
|
data = nullptr;
|
|
len = 0;
|
|
} else {
|
|
void* d = proto2_rust_alloc(src.length(), 1);
|
|
std::memcpy(d, src.data(), src.length());
|
|
data = static_cast<char*>(d);
|
|
len = src.length();
|
|
}
|
|
}
|
|
|
|
} // namespace rust
|
|
} // namespace protobuf
|
|
} // namespace google
|
|
|
|
extern "C" {
|
|
std::string* proto2_rust_cpp_new_string(google::protobuf::rust::PtrAndLen src) {
|
|
return new std::string(src.ptr, src.len);
|
|
}
|
|
|
|
void proto2_rust_cpp_delete_string(std::string* str) { delete str; }
|
|
|
|
google::protobuf::rust::PtrAndLen proto2_rust_cpp_string_to_view(std::string* str) {
|
|
return google::protobuf::rust::PtrAndLen{str->data(), str->length()};
|
|
}
|
|
}
|