diff options
author | 2015-06-04 12:53:40 -0700 | |
---|---|---|
committer | 2015-06-04 12:53:40 -0700 | |
commit | 50a7a68ca2a5ade22a97502389ec1e0d4dcb0a10 (patch) | |
tree | 072e2c0feee2c064e35c8f1d9f65dd2200ca1cfe /src/cpp/proto/proto_utils.cc | |
parent | a6ab47c75b80f85327f2e37c7c6865f1812059ba (diff) |
Progress commit on fixing up C++
Diffstat (limited to 'src/cpp/proto/proto_utils.cc')
-rw-r--r-- | src/cpp/proto/proto_utils.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/cpp/proto/proto_utils.cc b/src/cpp/proto/proto_utils.cc index 7a7e73bba4..a4a37c7000 100644 --- a/src/cpp/proto/proto_utils.cc +++ b/src/cpp/proto/proto_utils.cc @@ -31,7 +31,7 @@ * */ -#include "src/cpp/proto/proto_utils.h" +#include <grpc++/impl/proto_utils.h> #include <grpc++/config.h> #include <grpc/grpc.h> @@ -157,15 +157,23 @@ bool SerializeProto(const grpc::protobuf::Message& msg, grpc_byte_buffer** bp) { return msg.SerializeToZeroCopyStream(&writer); } -bool DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg, +Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg, int max_message_size) { - if (!buffer) return false; + if (!buffer) { + return Status(INVALID_ARGUMENT, "No payload"); + } GrpcBufferReader reader(buffer); ::grpc::protobuf::io::CodedInputStream decoder(&reader); if (max_message_size > 0) { decoder.SetTotalBytesLimit(max_message_size, max_message_size); } - return msg->ParseFromCodedStream(&decoder) && decoder.ConsumedEntireMessage(); + if (!msg->ParseFromCodedStream(&decoder)) { + return Status(INVALID_ARGUMENT, msg->InitializationErrorString()); + } + if (!decoder.ConsumedEntireMessage()) { + return Status(INVALID_ARGUMENT, "Did not read entire message"); + } + return Status::OK; } } // namespace grpc |