Remove `include/grpcpp/impl/codegen/proto_utils.h` (#31532)

pull/31768/head
Cheng-Yu Chung 2 years ago committed by GitHub
parent 31fc452b68
commit 5498481265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 2
      CMakeLists.txt
  3. 2
      build_autogenerated.yaml
  4. 1
      gRPC-C++.podspec
  5. 98
      include/grpcpp/impl/codegen/proto_utils.h
  6. 119
      include/grpcpp/impl/proto_utils.h
  7. 2
      src/compiler/cpp_generator.cc
  8. 2
      test/cpp/codegen/compiler_test_golden
  9. 2
      test/cpp/codegen/proto_utils_test.cc
  10. 2
      test/cpp/end2end/client_callback_end2end_test.cc
  11. 2
      test/cpp/end2end/client_interceptors_end2end_test.cc
  12. 2
      test/cpp/end2end/delegating_channel_test.cc
  13. 2
      test/cpp/end2end/filter_end2end_test.cc
  14. 2
      test/cpp/end2end/generic_end2end_test.cc
  15. 2
      test/cpp/end2end/server_interceptors_end2end_test.cc
  16. 1
      tools/doxygen/Doxyfile.c++
  17. 1
      tools/doxygen/Doxyfile.c++.internal

@ -1858,6 +1858,7 @@ grpc_cc_library(
"include/grpcpp/impl/codegen/proto_buffer_reader.h",
"include/grpcpp/impl/codegen/proto_buffer_writer.h",
"include/grpcpp/impl/codegen/proto_utils.h",
"include/grpcpp/impl/proto_utils.h",
],
tags = ["nofixdeps"],
visibility = ["@grpc:public"],

2
CMakeLists.txt generated

@ -3460,6 +3460,7 @@ foreach(_hdr
include/grpcpp/impl/interceptor_common.h
include/grpcpp/impl/metadata_map.h
include/grpcpp/impl/method_handler_impl.h
include/grpcpp/impl/proto_utils.h
include/grpcpp/impl/rpc_method.h
include/grpcpp/impl/rpc_service_method.h
include/grpcpp/impl/serialization_traits.h
@ -4155,6 +4156,7 @@ foreach(_hdr
include/grpcpp/impl/interceptor_common.h
include/grpcpp/impl/metadata_map.h
include/grpcpp/impl/method_handler_impl.h
include/grpcpp/impl/proto_utils.h
include/grpcpp/impl/rpc_method.h
include/grpcpp/impl/rpc_service_method.h
include/grpcpp/impl/serialization_traits.h

@ -2833,6 +2833,7 @@ libs:
- include/grpcpp/impl/interceptor_common.h
- include/grpcpp/impl/metadata_map.h
- include/grpcpp/impl/method_handler_impl.h
- include/grpcpp/impl/proto_utils.h
- include/grpcpp/impl/rpc_method.h
- include/grpcpp/impl/rpc_service_method.h
- include/grpcpp/impl/serialization_traits.h
@ -3259,6 +3260,7 @@ libs:
- include/grpcpp/impl/interceptor_common.h
- include/grpcpp/impl/metadata_map.h
- include/grpcpp/impl/method_handler_impl.h
- include/grpcpp/impl/proto_utils.h
- include/grpcpp/impl/rpc_method.h
- include/grpcpp/impl/rpc_service_method.h
- include/grpcpp/impl/serialization_traits.h

1
gRPC-C++.podspec generated

@ -154,6 +154,7 @@ Pod::Spec.new do |s|
'include/grpcpp/impl/interceptor_common.h',
'include/grpcpp/impl/metadata_map.h',
'include/grpcpp/impl/method_handler_impl.h',
'include/grpcpp/impl/proto_utils.h',
'include/grpcpp/impl/rpc_method.h',
'include/grpcpp/impl/rpc_service_method.h',
'include/grpcpp/impl/serialization_traits.h',

@ -21,101 +21,7 @@
// IWYU pragma: private
#include <type_traits>
#include <grpc/impl/codegen/byte_buffer_reader.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/impl/codegen/slice.h>
#include <grpcpp/impl/codegen/config_protobuf.h>
#include <grpcpp/impl/codegen/core_codegen_interface.h>
#include <grpcpp/impl/codegen/proto_buffer_reader.h>
#include <grpcpp/impl/codegen/proto_buffer_writer.h>
#include <grpcpp/impl/codegen/serialization_traits.h>
#include <grpcpp/impl/codegen/slice.h>
#include <grpcpp/impl/codegen/status.h>
#include <grpcpp/support/byte_buffer.h>
/// This header provides serialization and deserialization between gRPC
/// messages serialized using protobuf and the C++ objects they represent.
namespace grpc {
extern CoreCodegenInterface* g_core_codegen_interface;
// ProtoBufferWriter must be a subclass of ::protobuf::io::ZeroCopyOutputStream.
template <class ProtoBufferWriter, class T>
Status GenericSerialize(const grpc::protobuf::MessageLite& msg, ByteBuffer* bb,
bool* own_buffer) {
static_assert(std::is_base_of<protobuf::io::ZeroCopyOutputStream,
ProtoBufferWriter>::value,
"ProtoBufferWriter must be a subclass of "
"::protobuf::io::ZeroCopyOutputStream");
*own_buffer = true;
int byte_size = static_cast<int>(msg.ByteSizeLong());
if (static_cast<size_t>(byte_size) <= GRPC_SLICE_INLINED_SIZE) {
Slice slice(byte_size);
// We serialize directly into the allocated slices memory
GPR_CODEGEN_ASSERT(slice.end() == msg.SerializeWithCachedSizesToArray(
const_cast<uint8_t*>(slice.begin())));
ByteBuffer tmp(&slice, 1);
bb->Swap(&tmp);
return g_core_codegen_interface->ok();
}
ProtoBufferWriter writer(bb, kProtoBufferWriterMaxBufferLength, byte_size);
return msg.SerializeToZeroCopyStream(&writer)
? g_core_codegen_interface->ok()
: Status(StatusCode::INTERNAL, "Failed to serialize message");
}
// BufferReader must be a subclass of ::protobuf::io::ZeroCopyInputStream.
template <class ProtoBufferReader, class T>
Status GenericDeserialize(ByteBuffer* buffer,
grpc::protobuf::MessageLite* msg) {
static_assert(std::is_base_of<protobuf::io::ZeroCopyInputStream,
ProtoBufferReader>::value,
"ProtoBufferReader must be a subclass of "
"::protobuf::io::ZeroCopyInputStream");
if (buffer == nullptr) {
return Status(StatusCode::INTERNAL, "No payload");
}
Status result = g_core_codegen_interface->ok();
{
ProtoBufferReader reader(buffer);
if (!reader.status().ok()) {
return reader.status();
}
if (!msg->ParseFromZeroCopyStream(&reader)) {
result = Status(StatusCode::INTERNAL, msg->InitializationErrorString());
}
}
buffer->Clear();
return result;
}
// this is needed so the following class does not conflict with protobuf
// serializers that utilize internal-only tools.
#ifdef GRPC_OPEN_SOURCE_PROTO
// This class provides a protobuf serializer. It translates between protobuf
// objects and grpc_byte_buffers. More information about SerializationTraits can
// be found in include/grpcpp/impl/codegen/serialization_traits.h.
template <class T>
class SerializationTraits<
T, typename std::enable_if<
std::is_base_of<grpc::protobuf::MessageLite, T>::value>::type> {
public:
static Status Serialize(const grpc::protobuf::MessageLite& msg,
ByteBuffer* bb, bool* own_buffer) {
return GenericSerialize<ProtoBufferWriter, T>(msg, bb, own_buffer);
}
static Status Deserialize(ByteBuffer* buffer,
grpc::protobuf::MessageLite* msg) {
return GenericDeserialize<ProtoBufferReader, T>(buffer, msg);
}
};
#endif
} // namespace grpc
/// TODO(chengyuc): Remove this file after solving compatibility.
#include <grpcpp/impl/proto_utils.h>
#endif // GRPCPP_IMPL_CODEGEN_PROTO_UTILS_H

@ -0,0 +1,119 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_IMPL_PROTO_UTILS_H
#define GRPCPP_IMPL_PROTO_UTILS_H
#include <type_traits>
#include <grpc/byte_buffer_reader.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/slice.h>
#include <grpcpp/impl/codegen/config_protobuf.h>
#include <grpcpp/impl/codegen/core_codegen_interface.h>
#include <grpcpp/impl/serialization_traits.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/proto_buffer_reader.h>
#include <grpcpp/support/proto_buffer_writer.h>
#include <grpcpp/support/slice.h>
#include <grpcpp/support/status.h>
/// This header provides serialization and deserialization between gRPC
/// messages serialized using protobuf and the C++ objects they represent.
namespace grpc {
extern CoreCodegenInterface* g_core_codegen_interface;
// ProtoBufferWriter must be a subclass of ::protobuf::io::ZeroCopyOutputStream.
template <class ProtoBufferWriter, class T>
Status GenericSerialize(const grpc::protobuf::MessageLite& msg, ByteBuffer* bb,
bool* own_buffer) {
static_assert(std::is_base_of<protobuf::io::ZeroCopyOutputStream,
ProtoBufferWriter>::value,
"ProtoBufferWriter must be a subclass of "
"::protobuf::io::ZeroCopyOutputStream");
*own_buffer = true;
int byte_size = static_cast<int>(msg.ByteSizeLong());
if (static_cast<size_t>(byte_size) <= GRPC_SLICE_INLINED_SIZE) {
Slice slice(byte_size);
// We serialize directly into the allocated slices memory
GPR_CODEGEN_ASSERT(slice.end() == msg.SerializeWithCachedSizesToArray(
const_cast<uint8_t*>(slice.begin())));
ByteBuffer tmp(&slice, 1);
bb->Swap(&tmp);
return g_core_codegen_interface->ok();
}
ProtoBufferWriter writer(bb, kProtoBufferWriterMaxBufferLength, byte_size);
return msg.SerializeToZeroCopyStream(&writer)
? g_core_codegen_interface->ok()
: Status(StatusCode::INTERNAL, "Failed to serialize message");
}
// BufferReader must be a subclass of ::protobuf::io::ZeroCopyInputStream.
template <class ProtoBufferReader, class T>
Status GenericDeserialize(ByteBuffer* buffer,
grpc::protobuf::MessageLite* msg) {
static_assert(std::is_base_of<protobuf::io::ZeroCopyInputStream,
ProtoBufferReader>::value,
"ProtoBufferReader must be a subclass of "
"::protobuf::io::ZeroCopyInputStream");
if (buffer == nullptr) {
return Status(StatusCode::INTERNAL, "No payload");
}
Status result = g_core_codegen_interface->ok();
{
ProtoBufferReader reader(buffer);
if (!reader.status().ok()) {
return reader.status();
}
if (!msg->ParseFromZeroCopyStream(&reader)) {
result = Status(StatusCode::INTERNAL, msg->InitializationErrorString());
}
}
buffer->Clear();
return result;
}
// this is needed so the following class does not conflict with protobuf
// serializers that utilize internal-only tools.
#ifdef GRPC_OPEN_SOURCE_PROTO
// This class provides a protobuf serializer. It translates between protobuf
// objects and grpc_byte_buffers. More information about SerializationTraits can
// be found in include/grpcpp/impl/codegen/serialization_traits.h.
template <class T>
class SerializationTraits<
T, typename std::enable_if<
std::is_base_of<grpc::protobuf::MessageLite, T>::value>::type> {
public:
static Status Serialize(const grpc::protobuf::MessageLite& msg,
ByteBuffer* bb, bool* own_buffer) {
return GenericSerialize<ProtoBufferWriter, T>(msg, bb, own_buffer);
}
static Status Deserialize(ByteBuffer* buffer,
grpc::protobuf::MessageLite* msg) {
return GenericDeserialize<ProtoBufferReader, T>(buffer, msg);
}
};
#endif
} // namespace grpc
#endif // GRPCPP_IMPL_PROTO_UTILS_H

@ -145,7 +145,7 @@ std::string GetHeaderIncludes(grpc_generator::File* file,
"grpcpp/completion_queue.h",
"grpcpp/support/message_allocator.h",
"grpcpp/support/method_handler.h",
"grpcpp/impl/codegen/proto_utils.h",
"grpcpp/impl/proto_utils.h",
"grpcpp/impl/rpc_method.h",
"grpcpp/support/server_callback.h",
"grpcpp/impl/server_callback_handlers.h",

@ -35,7 +35,7 @@
#include <grpcpp/completion_queue.h>
#include <grpcpp/support/message_allocator.h>
#include <grpcpp/support/method_handler.h>
#include <grpcpp/impl/codegen/proto_utils.h>
#include <grpcpp/impl/proto_utils.h>
#include <grpcpp/impl/rpc_method.h>
#include <grpcpp/support/server_callback.h>
#include <grpcpp/impl/server_callback_handlers.h>

@ -20,8 +20,8 @@
#include <grpc/byte_buffer.h>
#include <grpc/slice.h>
#include <grpcpp/impl/codegen/proto_utils.h>
#include <grpcpp/impl/grpc_library.h>
#include <grpcpp/impl/proto_utils.h>
#include "test/core/util/test_config.h"

@ -31,7 +31,7 @@
#include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/generic/generic_stub.h>
#include <grpcpp/impl/codegen/proto_utils.h>
#include <grpcpp/impl/proto_utils.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h>

@ -28,7 +28,7 @@
#include <grpcpp/create_channel.h>
#include <grpcpp/create_channel_posix.h>
#include <grpcpp/generic/generic_stub.h>
#include <grpcpp/impl/codegen/proto_utils.h>
#include <grpcpp/impl/proto_utils.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h>

@ -25,8 +25,8 @@
#include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/generic/generic_stub.h>
#include <grpcpp/impl/codegen/proto_utils.h>
#include <grpcpp/impl/delegating_channel.h>
#include <grpcpp/impl/proto_utils.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h>

@ -31,7 +31,7 @@
#include <grpcpp/create_channel.h>
#include <grpcpp/generic/async_generic_service.h>
#include <grpcpp/generic/generic_stub.h>
#include <grpcpp/impl/codegen/proto_utils.h>
#include <grpcpp/impl/proto_utils.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h>

@ -30,7 +30,7 @@
#include <grpcpp/create_channel.h>
#include <grpcpp/generic/async_generic_service.h>
#include <grpcpp/generic/generic_stub.h>
#include <grpcpp/impl/codegen/proto_utils.h>
#include <grpcpp/impl/proto_utils.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h>

@ -28,7 +28,7 @@
#include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/generic/generic_stub.h>
#include <grpcpp/impl/codegen/proto_utils.h>
#include <grpcpp/impl/proto_utils.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h>

@ -1019,6 +1019,7 @@ include/grpcpp/impl/intercepted_channel.h \
include/grpcpp/impl/interceptor_common.h \
include/grpcpp/impl/metadata_map.h \
include/grpcpp/impl/method_handler_impl.h \
include/grpcpp/impl/proto_utils.h \
include/grpcpp/impl/rpc_method.h \
include/grpcpp/impl/rpc_service_method.h \
include/grpcpp/impl/serialization_traits.h \

@ -1019,6 +1019,7 @@ include/grpcpp/impl/intercepted_channel.h \
include/grpcpp/impl/interceptor_common.h \
include/grpcpp/impl/metadata_map.h \
include/grpcpp/impl/method_handler_impl.h \
include/grpcpp/impl/proto_utils.h \
include/grpcpp/impl/rpc_method.h \
include/grpcpp/impl/rpc_service_method.h \
include/grpcpp/impl/serialization_traits.h \

Loading…
Cancel
Save