Issue Parsing doubles in nested objects C++

14 views
Skip to first unread message

Timothy Sutton

unread,
Sep 23, 2022, 4:38:28 PMSep 23
to Protocol Buffers
I am having issues parsing messages with doubles inside of C++ they seem to end up always zero when I parse them. I can seem that int fields are being populated with the correct data, but not doubles. I tried using both the 3.21 and 3.15 libraries to no success. If I parse these same messages with my java application I see that I get the results as expected. 

Has anyone seen a similar problem? 

Derek Perez

unread,
Sep 23, 2022, 4:52:25 PMSep 23
to Timothy Sutton, Protocol Buffers
Can you provide a reproduction for us?

On Fri, Sep 23, 2022 at 1:38 PM Timothy Sutton <timothy...@saabusa.com> wrote:
I am having issues parsing messages with doubles inside of C++ they seem to end up always zero when I parse them. I can seem that int fields are being populated with the correct data, but not doubles. I tried using both the 3.21 and 3.15 libraries to no success. If I parse these same messages with my java application I see that I get the results as expected. 

Has anyone seen a similar problem? 

--
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/f2aeb80a-0e16-4c26-beda-d58b13f4a579n%40googlegroups.com.

Timothy Sutton

unread,
Sep 30, 2022, 9:26:17 AMSep 30
to Protocol Buffers
My problem here was that I was using I was using ParseFromString, after reading from socket. In order to get this to work I had to use ParseFromArray. 


Not working code

            len = recvfrom(sockfd, buffer, MAX_LENGTH ,
            MSG_WAITALL, (struct sockaddr*) &cliaddr, (socklen_t*) &size);

            if (len > 0) {
                // Add ending string to buffer.
                buffer[len] = '\0';
                string data = string(buffer)
                common::Message message;
                if (message.ParseFromString(data)) {

working code
            len = recvfrom(sockfd, buffer, MAX_LENGTH ,
            MSG_WAITALL, (struct sockaddr*) &cliaddr, (socklen_t*) &size);

            if (len > 0) {
                // Add ending string to buffer.
                buffer[len] = '\0';
                common::Message message;
                if (! message  .ParseFromArray(buffer, len+1)) { 
Reply all
Reply to author
Forward
0 new messages