From 058070d706c85d650ab001e31e6489e2ba07d643 Mon Sep 17 00:00:00 2001 From: ni-sujain <98735487+ni-sujain@users.noreply.github.com> Date: Mon, 8 May 2023 09:02:20 +0530 Subject: [PATCH] Return Unavailable status if not able to parse request (#254) --- src/event_data.cc | 17 ++++++++++++----- src/lv_message.cc | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/event_data.cc b/src/event_data.cc index 3823c8ec..f49d5096 100644 --- a/src/event_data.cc +++ b/src/event_data.cc @@ -199,12 +199,19 @@ namespace grpc_labview auto responseMetadata = _server->FindMetadata(eventData.responseMetadataName); _request = std::make_shared(requestMetadata); _response = std::make_shared(responseMetadata); - _request->ParseFromByteBuffer(_rb); - _requestDataReady = true; - _methodData = std::make_shared(this, &_ctx, _request, _response); - gPointerManager.RegisterPointer(_methodData); - _server->SendEvent(name, static_cast(_methodData.get())); + if (_request->ParseFromByteBuffer(_rb)) + { + _requestDataReady = true; + _methodData = std::make_shared(this, &_ctx, _request, _response); + gPointerManager.RegisterPointer(_methodData); + _server->SendEvent(name, static_cast(_methodData.get())); + } + else + { + _status = CallStatus::Finish; + _stream.Finish(grpc::Status(grpc::StatusCode::UNAVAILABLE, ""), this); + } } else { diff --git a/src/lv_message.cc b/src/lv_message.cc index 8edfd40b..6395da1b 100644 --- a/src/lv_message.cc +++ b/src/lv_message.cc @@ -165,6 +165,10 @@ namespace grpc_labview } else { + if (tag == 0 || WireFormatLite::GetTagWireType(tag) == WireFormatLite::WIRETYPE_END_GROUP) { + ctx->SetLastTag(tag); + return ptr; + } ptr = UnknownFieldParse(tag, &_unknownFields, ptr, ctx); assert(ptr != nullptr); }