You can use an extra layer of curly-brace nesting to ensure the CodedOutputStream is destroyed before you examine the output. See this test code <https://github.com/protocolbuffers/protobuf/blob/f38b6ed041107330b7453def5139438b0b3e5978/src/google/protobuf/io/coded_stream_unittest.cc#L341> for example. I think if you let the CodedOutputStream be destroyed first then that will fix the problem with your StringOutputStream code.
On Mon, Jul 29, 2019 at 1:42 PM Rinka Yoshida <[email protected]> wrote: > I'm experiencing the same issue too and I was wondering if you could > please elaborate on what you mean by destroying it before using its output? > Delete OstreamOutputStream and try to get the string contained in > stringstream? > > I tried using StringOutputStream, but it seems like when I did > coded_output->WriteString(serialized_string), sometimes serialized_string's > content will be chopped off. I was wondering if you also might have any > idea why this is happening. > > On Sunday, April 14, 2013 at 1:59:26 PM UTC-7, Oliver Jowett wrote: >> >> On Sun, Apr 14, 2013 at 7:26 PM, Predator33 <[email protected]> wrote: >> >>> The only thing I could think of is maybe the protobuf stream doesn't >>> flush itself out until the destructor is hit and since that never happens >>> until after the fact, it never gets flushed? >>> >> >> Yes, this will be what is happening. Arrange for the OstreamOutputStream >> to be destroyed before you try to use its output (e.g. wrap that >> declaration in another level of nesting) >> >> Is there some reason why you're using stringstream + OstreamOutputStream, >> rather than just using StringOutputStream? >> >> Oliver >> >> -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/protobuf/dfc6c277-349f-465a-81d9-f87c8de84985%40googlegroups.com > <https://groups.google.com/d/msgid/protobuf/dfc6c277-349f-465a-81d9-f87c8de84985%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/CADqAXr6hFrd8gVgKNHqUKAn-A6y6xHcpbA-vf3Ns6U%3Dzc6%3DGDg%40mail.gmail.com.
