MessageToJsonString() throws std::system_error

29 views
Skip to first unread message

A

unread,
Aug 6, 2019, 2:44:34 AM8/6/19
to Protocol Buffers

I'm trying to dump the protobuf message object using MessageToJsonString() function but encountering an exception. Sample code is as below followed by the output without try{}catch()


ResultRecord* GetSampleData()
{
    auto resultRecord = std::make_unique<ResultRecord>();
    ....
    //Filling resultRecord
    ....
    return resultRecord.release();
}
int main(int, char**) {

    //Getting RecordData through Protobuf
    auto data = GetSampleData();

    if(data){
        std::string str;
        google::protobuf::util::JsonOptions opts;
        opts.add_whitespace = true;
        try{
            google::protobuf::util::MessageToJsonString(*(data), &str, opts);
        }
        catch(std::exception e)
        {
            std::cout<< e.what()<<std::endl;
        }
        std::cout<<str<<std::endl;
    }
    return 0;
}
Output :
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1

I'm not sure what to do to debug this. Can someone point me in right direction ?

Adam Cozzette

unread,
Aug 6, 2019, 2:42:25 PM8/6/19
to A, Protocol Buffers
I replied on your GitHub issue here: https://github.com/protocolbuffers/protobuf/issues/6479

--
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 protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/e4f70f39-40cb-4801-9c96-da46e3dd3830%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages