Migrate ::hpb::internal::GetMiniTable to ::hpb::interop::upb::GetMiniTable hpb.h now shows signs of backend-awareness, #including upb.h if the backend is known to be upb. If no backend is picked, we error out at this time since we solely support upb. ClearMessage has been migrated to backend-aware hpb. PiperOrigin-RevId: 665527832pull/17885/head
parent
b817373e6b
commit
8bb789e462
9 changed files with 130 additions and 29 deletions
@ -0,0 +1,38 @@ |
||||
# Copyright (c) 2024, Google LLC |
||||
# All rights reserved. |
||||
# |
||||
# Use of this source code is governed by a BSD-style |
||||
# license that can be found in the LICENSE file or at |
||||
# https://developers.google.com/open-source/licenses/bsd |
||||
|
||||
# begin:google_only |
||||
# package(default_applicable_licenses = ["//src/google/protobuf:license"]) |
||||
# end:google_only |
||||
|
||||
cc_library( |
||||
name = "upb", |
||||
hdrs = ["upb.h"], |
||||
compatible_with = ["//buildenv/target:non_prod"], |
||||
visibility = ["//upb:friends"], |
||||
deps = [ |
||||
":interop", |
||||
"//hpb:ptr", |
||||
"//hpb/internal", |
||||
"//hpb/internal:template_help", |
||||
"//upb:mini_table", |
||||
], |
||||
) |
||||
|
||||
cc_library( |
||||
name = "interop", |
||||
hdrs = ["interop.h"], |
||||
compatible_with = ["//buildenv/target:non_prod"], |
||||
visibility = [ |
||||
"//hpb:__subpackages__", |
||||
"//protos:__pkg__", |
||||
], |
||||
deps = [ |
||||
"//hpb:ptr", |
||||
"//upb:mini_table", |
||||
], |
||||
) |
@ -0,0 +1,30 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2024 Google LLC. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_HPB_BACKEND_UPB_INTEROP_H__ |
||||
#define GOOGLE_PROTOBUF_HPB_BACKEND_UPB_INTEROP_H__ |
||||
|
||||
// The sole public header in hpb/backend/upb
|
||||
|
||||
#include "google/protobuf/hpb/ptr.h" |
||||
#include "upb/mini_table/message.h" |
||||
|
||||
namespace hpb::interop::upb { |
||||
|
||||
template <typename T> |
||||
const upb_MiniTable* GetMiniTable(const T*) { |
||||
return T::minitable(); |
||||
} |
||||
|
||||
template <typename T> |
||||
const upb_MiniTable* GetMiniTable(Ptr<T>) { |
||||
return T::minitable(); |
||||
} |
||||
|
||||
} // namespace hpb::interop::upb
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_HPB_BACKEND_UPB_INTEROP_H__
|
@ -0,0 +1,27 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2024 Google LLC. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_HPB_BACKEND_UPB_UPB_H__ |
||||
#define GOOGLE_PROTOBUF_HPB_BACKEND_UPB_UPB_H__ |
||||
|
||||
#include "google/protobuf/hpb/backend/upb/interop.h" |
||||
#include "google/protobuf/hpb/internal/internal.h" |
||||
#include "google/protobuf/hpb/internal/template_help.h" |
||||
#include "google/protobuf/hpb/ptr.h" |
||||
|
||||
namespace hpb::internal::backend::upb { |
||||
|
||||
template <typename T> |
||||
void ClearMessage(hpb::internal::PtrOrRaw<T> message) { |
||||
auto ptr = Ptr(message); |
||||
auto minitable = hpb::interop::upb::GetMiniTable(ptr); |
||||
upb_Message_Clear(hpb::internal::GetInternalMsg(ptr), minitable); |
||||
} |
||||
|
||||
} // namespace hpb::internal::backend::upb
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_HPB_BACKEND_UPB_UPB_H__
|
Loading…
Reference in new issue