Introduce hpb/internal/internal.h

Moved PrivateAccess and some helper funcs

PiperOrigin-RevId: 664831322
pull/17857/head
Hong Shin 3 months ago committed by Copybara-Service
parent 025909cb53
commit f5f94f334b
  1. 1
      hpb/BUILD
  2. 40
      hpb/hpb.h
  3. 11
      hpb/internal/BUILD
  4. 53
      hpb/internal/internal.h

@ -55,6 +55,7 @@ cc_library(
deps = [
":extension_lock",
"//hpb:ptr",
"//hpb/internal",
"//hpb/internal:template_help",
"//upb:base",
"//upb:mem",

@ -15,6 +15,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/hpb/internal/internal.h"
#include "google/protobuf/hpb/internal/template_help.h"
#include "google/protobuf/hpb/ptr.h"
#include "upb/base/status.hpp"
@ -69,45 +70,6 @@ absl::Status MessageEncodeError(upb_EncodeStatus status,
SourceLocation loc = SourceLocation::current());
namespace internal {
struct PrivateAccess {
template <typename T>
static auto* GetInternalMsg(T&& message) {
return message->msg();
}
template <typename T>
static auto Proxy(upb_Message* p, upb_Arena* arena) {
return typename T::Proxy(p, arena);
}
template <typename T>
static auto CProxy(const upb_Message* p, upb_Arena* arena) {
return typename T::CProxy(p, arena);
}
template <typename T>
static auto CreateMessage(upb_Arena* arena) {
return typename T::Proxy(upb_Message_New(T::minitable(), arena), arena);
}
template <typename ExtensionId>
static constexpr uint32_t GetExtensionNumber(const ExtensionId& id) {
return id.number();
}
};
template <typename T>
auto* GetInternalMsg(T&& message) {
return PrivateAccess::GetInternalMsg(std::forward<T>(message));
}
template <typename T>
typename T::Proxy CreateMessageProxy(upb_Message* msg, upb_Arena* arena) {
return typename T::Proxy(msg, arena);
}
template <typename T>
typename T::CProxy CreateMessage(const upb_Message* msg, upb_Arena* arena) {
return PrivateAccess::CProxy<T>(msg, arena);
}
class ExtensionMiniTableProvider {
public:
constexpr explicit ExtensionMiniTableProvider(

@ -18,3 +18,14 @@ cc_library(
"//hpb:ptr",
],
)
cc_library(
name = "internal",
hdrs = ["internal.h"],
compatible_with = ["//buildenv/target:non_prod"],
visibility = ["//hpb:__subpackages__"],
deps = [
"//upb:mem",
"//upb:message",
],
)

@ -0,0 +1,53 @@
#ifndef GOOGLE_PROTOBUF_HPB_INTERNAL_INTERNAL_H__
#define GOOGLE_PROTOBUF_HPB_INTERNAL_INTERNAL_H__
#include <cstdint>
#include <utility>
#include "upb/mem/arena.h"
#include "upb/message/message.h"
namespace hpb::internal {
struct PrivateAccess {
template <typename T>
static auto* GetInternalMsg(T&& message) {
return message->msg();
}
template <typename T>
static auto Proxy(upb_Message* p, upb_Arena* arena) {
return typename T::Proxy(p, arena);
}
template <typename T>
static auto CProxy(const upb_Message* p, upb_Arena* arena) {
return typename T::CProxy(p, arena);
}
template <typename T>
static auto CreateMessage(upb_Arena* arena) {
return typename T::Proxy(upb_Message_New(T::minitable(), arena), arena);
}
template <typename ExtensionId>
static constexpr uint32_t GetExtensionNumber(const ExtensionId& id) {
return id.number();
}
};
template <typename T>
auto* GetInternalMsg(T&& message) {
return PrivateAccess::GetInternalMsg(std::forward<T>(message));
}
template <typename T>
typename T::Proxy CreateMessageProxy(upb_Message* msg, upb_Arena* arena) {
return typename T::Proxy(msg, arena);
}
template <typename T>
typename T::CProxy CreateMessage(const upb_Message* msg, upb_Arena* arena) {
return PrivateAccess::CProxy<T>(msg, arena);
}
} // namespace hpb::internal
#endif // GOOGLE_PROTOBUF_HPB_INTERNAL_INTERNAL_H__
Loading…
Cancel
Save