From 6a7ec85e83be45efd7ddc4f6a7a34ca099e9f6e7 Mon Sep 17 00:00:00 2001 From: Lawrence Chan Date: Fri, 12 May 2017 16:36:35 -0500 Subject: [PATCH] [C++] Fix code gen indentation when empty Print (#4313) * Fix C++ code gen indentation when empty Print * Also commit modified tests/monster_test.bfbs --- src/idl_gen_grpc.cpp | 3 +++ tests/monster_test.bfbs | Bin 4320 -> 4288 bytes tests/monster_test.grpc.fb.h | 12 ++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/idl_gen_grpc.cpp b/src/idl_gen_grpc.cpp index 5bd0b0362..52926821d 100644 --- a/src/idl_gen_grpc.cpp +++ b/src/idl_gen_grpc.cpp @@ -154,6 +154,9 @@ class FlatBufPrinter : public grpc_generator::Printer { } void Print(const char *s) { + if (s == nullptr || std::strlen(s) == 0) { + return; + } // Add this string, but for each part separated by \n, add indentation. for (;;) { // Current indentation. diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index 516b764ef2ffb9e3aae7c083ed55f57bafe5ea12..78871d504af00b89b914a99875abdce6801b38b7 100644 GIT binary patch literal 4288 zcmai1O=uNY6h1GB`O#+*W2$LPWh@ecgoh?UM2f_;#Z~(JT-E%Cyjian&6H^4th?ZQZ?nI( z>|PH2u!`3ji;L)|K;(O9^fX%=en{leF6v~X&I!NnaomaZERZemh#Y)UKlyE3wqSg+ z>UjbBW6IAATjQtRwBMMjU1z<#1gf9%sohAYd=mXT0vZSH10_D5iHcrz8ksUvaTmSZ zWHl_m8Z7$tJPoE_4(RT$x)&YR#w=vhFY5!fIiRhe1U={anBa}!Gi!Sx$HtqoKL+gr zt&6waM%jzC{YajY?tQEQV!H zjygD=JO)mp)EW#Ta+u z)R}e{_yL?|?xF*t44&&WKB|_2b0Z?3K21ImvB`tB;N}^z8*NAX);hV%&?}-&9`; zH)n9jYMeQYcglfha5gS!|HymU;MBj)KjOFt6)mkVjkEp{ciZ69ze(VB$l#_p>mPBe z2B-dA0`+XndPGl(cklz8( z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If*9v?rVKX%FGt<-Qs4D19iK>4jXgY*e!{;-Mh4%Nn>}5sx6Y3 z0E%|=Tr7~WoAKb8oCWO!@zB0Q_bI5!8J%`Am*-k& request, flatbuffers::BufferRef* response) = 0; + virtual ::grpc::Status Store(::grpc::ClientContext* context, const flatbuffers::BufferRef& request, flatbuffers::BufferRef* response) = 0; std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< flatbuffers::BufferRef>> AsyncStore(::grpc::ClientContext* context, const flatbuffers::BufferRef& request, ::grpc::CompletionQueue* cq) { return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< flatbuffers::BufferRef>>(AsyncStoreRaw(context, request, cq)); } - std::unique_ptr< ::grpc::ClientReaderInterface< flatbuffers::BufferRef>> Retrieve(::grpc::ClientContext* context, const flatbuffers::BufferRef& request) { + std::unique_ptr< ::grpc::ClientReaderInterface< flatbuffers::BufferRef>> Retrieve(::grpc::ClientContext* context, const flatbuffers::BufferRef& request) { return std::unique_ptr< ::grpc::ClientReaderInterface< flatbuffers::BufferRef>>(RetrieveRaw(context, request)); } std::unique_ptr< ::grpc::ClientAsyncReaderInterface< flatbuffers::BufferRef>> AsyncRetrieve(::grpc::ClientContext* context, const flatbuffers::BufferRef& request, ::grpc::CompletionQueue* cq, void* tag) { return std::unique_ptr< ::grpc::ClientAsyncReaderInterface< flatbuffers::BufferRef>>(AsyncRetrieveRaw(context, request, cq, tag)); } - private: + private: virtual ::grpc::ClientAsyncResponseReaderInterface< flatbuffers::BufferRef>* AsyncStoreRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef& request, ::grpc::CompletionQueue* cq) = 0; virtual ::grpc::ClientReaderInterface< flatbuffers::BufferRef>* RetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef& request) = 0; virtual ::grpc::ClientAsyncReaderInterface< flatbuffers::BufferRef>* AsyncRetrieveRaw(::grpc::ClientContext* context, const flatbuffers::BufferRef& request, ::grpc::CompletionQueue* cq, void* tag) = 0; @@ -79,9 +79,9 @@ class MonsterStorage final { public: Service(); virtual ~Service(); - virtual ::grpc::Status Store(::grpc::ServerContext* context, const flatbuffers::BufferRef* request, flatbuffers::BufferRef* response); - virtual ::grpc::Status Retrieve(::grpc::ServerContext* context, const flatbuffers::BufferRef* request, ::grpc::ServerWriter< flatbuffers::BufferRef>* writer); - }; + virtual ::grpc::Status Store(::grpc::ServerContext* context, const flatbuffers::BufferRef* request, flatbuffers::BufferRef* response); + virtual ::grpc::Status Retrieve(::grpc::ServerContext* context, const flatbuffers::BufferRef* request, ::grpc::ServerWriter< flatbuffers::BufferRef>* writer); + }; template class WithAsyncMethod_Store : public BaseClass { private: