Alex Rivera | Logout

Qt + protobuf, types?

Asked 2010-11-23T04:58:10.833
17

I would like to dip into Google's protocol buffers in Qt development, but I am having trouble figuring out how to incorporate them best.

Ultimately, I want to send with QUdpSocket and QTcpSocket using protocol buffers.

What is the best method for going between a protocol buffer message to sending the data over a socket (QByteArray) and then back again at the other side?

Edit
Report

1 Answer

3

@James: You can use ParseFromArray(), for example, as below: (Please note that ParseFromArray() is available only on proto-buf-lite versions of the libs).

void convertQByteArrayToUser(QByteArray& aByteArray)
{
    com::your::name_space::User user;
    if(!user.ParseFromArray(aByteArray.data(), aByteArray.size())) 
    {
        //could not parse
    }
    else { //yayyyyy            
        if(user.has_userid())
        {
            //...
        }
    }
}
answered 2011-02-10T08:03:12.607

Your Answer