-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce hpb::interop::upb and hpb::internal::backend::upb
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: 665527832
- Loading branch information
1 parent
b817373
commit 8bb789e
Showing
9 changed files
with
130 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters