aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc++
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2016-03-02 20:33:28 -0800
committerGravatar David Garcia Quintas <dgq@google.com>2016-03-02 20:33:28 -0800
commitf588aeb1e2033bc1421cd1dd1687f05ac7d49e64 (patch)
treef101ed17bf015fc1fe7527d83e8783e4eb4e6ab2 /include/grpc++
parent08745b0115ccb24fdca1081e9159a85c6f6a79d9 (diff)
introduced workaround for proto_utils
Diffstat (limited to 'include/grpc++')
-rw-r--r--include/grpc++/impl/codegen/proto_utils.h56
1 files changed, 46 insertions, 10 deletions
diff --git a/include/grpc++/impl/codegen/proto_utils.h b/include/grpc++/impl/codegen/proto_utils.h
index ce177104e0..489293d25b 100644
--- a/include/grpc++/impl/codegen/proto_utils.h
+++ b/include/grpc++/impl/codegen/proto_utils.h
@@ -37,21 +37,52 @@
#include <type_traits>
#include <grpc/impl/codegen/byte_buffer.h>
+#include <grpc/impl/codegen/log.h>
#include <grpc++/impl/codegen/serialization_traits.h>
#include <grpc++/impl/codegen/config_protobuf.h>
#include <grpc++/impl/codegen/status.h>
namespace grpc {
-// Serialize the msg into a buffer created inside the function. The caller
-// should destroy the returned buffer when done with it. If serialization fails,
-// false is returned and buffer is left unchanged.
-Status SerializeProto(const grpc::protobuf::Message& msg,
- grpc_byte_buffer** buffer);
+class ProtoSerializerInterface {
+ public:
+ // Serialize the msg into a buffer created inside the function. The caller
+ // should destroy the returned buffer when done with it. If serialization
+ // fails,
+ // false is returned and buffer is left unchanged.
+ virtual Status SerializeProto(const grpc::protobuf::Message& msg,
+ grpc_byte_buffer** buffer) = 0;
+
+ // The caller keeps ownership of buffer and msg.
+ virtual Status DeserializeProto(grpc_byte_buffer* buffer,
+ grpc::protobuf::Message* msg,
+ int max_message_size) = 0;
+};
+
+// TODO(dgq): This is a temporary fix to work around codegen issues related to
+// a certain sharp-sounding build system. Its purpose is to hold a polymorphic
+// proto serializer/deserializer instance. It's initialized as part of
+// src/cpp/proto/proto_serializer.cc.
+//
+// This global variable plus all related code (ProtoSerializerInteface,
+// ProtoSerializer) will be removed in the future.
+extern ProtoSerializerInterface* g_proto_serializer;
+
+class ProtoSerializer : public ProtoSerializerInterface {
+ public:
+ // Serialize the msg into a buffer created inside the function. The caller
+ // should destroy the returned buffer when done with it. If serialization
+ // fails,
+ // false is returned and buffer is left unchanged.
+ Status SerializeProto(const grpc::protobuf::Message& msg,
+ grpc_byte_buffer** buffer) override;
+
+ // The caller keeps ownership of buffer and msg.
+ Status DeserializeProto(grpc_byte_buffer* buffer,
+ grpc::protobuf::Message* msg,
+ int max_message_size) override;
+};
-// The caller keeps ownership of buffer and msg.
-Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg,
- int max_message_size);
template <class T>
class SerializationTraits<T, typename std::enable_if<std::is_base_of<
@@ -60,12 +91,17 @@ class SerializationTraits<T, typename std::enable_if<std::is_base_of<
static Status Serialize(const grpc::protobuf::Message& msg,
grpc_byte_buffer** buffer, bool* own_buffer) {
*own_buffer = true;
- return SerializeProto(msg, buffer);
+ GPR_ASSERT(g_proto_serializer != nullptr &&
+ "No ProtoSerializer instance registered. Make sure grpc++ is being initialized.");
+ return g_proto_serializer->SerializeProto(msg, buffer);
}
static Status Deserialize(grpc_byte_buffer* buffer,
grpc::protobuf::Message* msg,
int max_message_size) {
- auto status = DeserializeProto(buffer, msg, max_message_size);
+ GPR_ASSERT(g_proto_serializer != nullptr &&
+ "No ProtoSerializer instance registered. Make sure grpc++ is being initialized.");
+ auto status =
+ g_proto_serializer->DeserializeProto(buffer, msg, max_message_size);
grpc_byte_buffer_destroy(buffer);
return status;
}