diff options
author | ncteisen <ncteisen@gmail.com> | 2017-05-10 09:16:22 -0700 |
---|---|---|
committer | ncteisen <ncteisen@gmail.com> | 2017-05-10 09:16:22 -0700 |
commit | 22dbd73b4368cfce188b6f85505b287e710b4f11 (patch) | |
tree | 45cd4c0917386022736543ce481c2971d15012b8 /include/grpc++/impl/codegen | |
parent | fde16afefa41510c6dc06afd88bfd6c3002467b5 (diff) |
Add static assert to enforce subtype invariant
Diffstat (limited to 'include/grpc++/impl/codegen')
-rw-r--r-- | include/grpc++/impl/codegen/proto_utils.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/include/grpc++/impl/codegen/proto_utils.h b/include/grpc++/impl/codegen/proto_utils.h index a6e10cc8b6..5cdb2a7a15 100644 --- a/include/grpc++/impl/codegen/proto_utils.h +++ b/include/grpc++/impl/codegen/proto_utils.h @@ -183,10 +183,12 @@ class GrpcBufferReader : public ::grpc::protobuf::io::ZeroCopyInputStream { Status status_; }; -// BufferWriter must be a subclass of io::ZeroCopyOutputStream. template <class BufferWriter, class T> Status GenericSerialize(const grpc::protobuf::Message& msg, grpc_byte_buffer** bp, bool* own_buffer) { + static_assert( + std::is_base_of<protobuf::io::ZeroCopyOutputStream, BufferWriter>::value, + "BufferWriter must be a subclass of io::ZeroCopyOutputStream"); *own_buffer = true; int byte_size = msg.ByteSize(); if (byte_size <= internal::kGrpcBufferWriterMaxBufferLength) { @@ -205,10 +207,12 @@ Status GenericSerialize(const grpc::protobuf::Message& msg, } } -// BufferReader must be a subclass of io::ZeroCopyInputStream. template <class BufferReader, class T> Status GenericDeserialize(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg) { + static_assert( + std::is_base_of<protobuf::io::ZeroCopyInputStream, BufferReader>::value, + "BufferReader must be a subclass of io::ZeroCopyInputStream"); if (buffer == nullptr) { return Status(StatusCode::INTERNAL, "No payload"); } |