Skip to content

Commit

Permalink
Use pybind11_protobuf when passing Fingerprints.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 556081074
  • Loading branch information
BlaziusMaximus authored and copybara-github committed Aug 15, 2023
1 parent b2e7687 commit 016f754
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pybind11_protobuf/proto_caster_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,24 @@ struct proto_caster_load_impl {

// load converts from Python -> C++
bool load(pybind11::handle src, bool convert) {
LOG(ERROR) << 1;
// When given a none, treat it as a nullptr.
if (src.is_none()) {
value = nullptr;
return true;
}
LOG(ERROR) << 1;
// NOTE: We might need to know whether the proto has extensions that
// are python-only.

// Attempt to use the PyProto_API to get an underlying C++ message pointer
// from the object.
const ::google::protobuf::Message *message =
pybind11_protobuf::PyProtoGetCppMessagePointer(src);
LOG(ERROR) << 1;
if (message && message->GetReflection() ==
ProtoType::default_instance().GetReflection()) {
LOG(ERROR) << 1;
// If the capability were available, then we could probe PyProto_API and
// allow c++ mutability based on the python reference count.
value = static_cast<const ProtoType *>(message);
Expand All @@ -62,13 +66,17 @@ struct proto_caster_load_impl {

// The incoming object is not a compatible fast_cpp_proto, so check whether
// it is otherwise compatible, then serialize it and deserialize into a
LOG(ERROR) << 1;
// native C++ proto type.
if (!pybind11_protobuf::PyProtoIsCompatible(src,
ProtoType::GetDescriptor())) {
LOG(ERROR) << 1;
return false;
}
LOG(ERROR) << 1;
owned = std::unique_ptr<ProtoType>(new ProtoType());
value = owned.get();
LOG(ERROR) << 1;
return pybind11_protobuf::PyProtoCopyToCProto(src, owned.get());
}

Expand Down

0 comments on commit 016f754

Please sign in to comment.