hpb: Introduce HPB_INTERNAL_BACKEND and backend/cpp/cpp.h This abrogates HPB_BACKEND_UPB and HPB_BACKEND_CPP. The backend is now controlled by a string_flag, which defaults to upb. Note that INTERNAL was also added -- clarifying that this macro is for internal use only. This continues the multibackend work by stubbing the second backend in cpp.h. PiperOrigin-RevId: 750172782
diff --git a/hpb/backend/cpp/cpp.h b/hpb/backend/cpp/cpp.h new file mode 100644 index 0000000..4a0fa53 --- /dev/null +++ b/hpb/backend/cpp/cpp.h
@@ -0,0 +1,32 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2025 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_CPP_CPP_H__ +#define GOOGLE_PROTOBUF_HPB_BACKEND_CPP_CPP_H__ + +#include "absl/strings/string_view.h" +#include "google/protobuf/hpb/arena.h" +#include "google/protobuf/hpb/internal/template_help.h" + +namespace hpb::internal::backend::cpp { + +// hpb(cpp) backend stubs. + +template <typename T> +void ClearMessage(hpb::internal::PtrOrRawMutable<T> message) { + abort(); +} + +template <typename T> +absl::string_view Serialize(hpb::internal::PtrOrRaw<T> message, + hpb::Arena& arena) { + abort(); +} + +} // namespace hpb::internal::backend::cpp + +#endif // GOOGLE_PROTOBUF_HPB_BACKEND_CPP_CPP_H__
diff --git a/hpb/hpb.h b/hpb/hpb.h index 929e347..d47cd01 100644 --- a/hpb/hpb.h +++ b/hpb/hpb.h
@@ -23,16 +23,25 @@ #include "google/protobuf/hpb/status.h" #include "upb/wire/decode.h" -#ifdef HPB_BACKEND_UPB +#define HPB_INTERNAL_BACKEND_UPB 1 +#define HPB_INTERNAL_BACKEND_CPP 2 + +#if HPB_INTERNAL_BACKEND == HPB_INTERNAL_BACKEND_UPB #include "google/protobuf/hpb/backend/upb/upb.h" +#elif HPB_INTERNAL_BACKEND == HPB_INTERNAL_BACKEND_CPP +#include "google/protobuf/hpb/backend/cpp/cpp.h" #else -#error hpb backend must be specified +#error hpb backend unknown #endif namespace hpb { -#ifdef HPB_BACKEND_UPB +#if HPB_INTERNAL_BACKEND == HPB_INTERNAL_BACKEND_UPB namespace backend = internal::backend::upb; +#elif HPB_INTERNAL_BACKEND == HPB_INTERNAL_BACKEND_CPP +namespace backend = internal::backend::cpp; +#else +#error hpb backend unknown #endif template <typename T>