DebugString() for Any messages with Visual Studio (C++)

499 views
Skip to first unread message

Andreas Folkers

unread,
Nov 18, 2022, 4:40:37 AM11/18/22
to Protocol Buffers
I would like to print a debug message for a type (let's say the type is 'MessageType'), that is not known at compile time. It works fine when compiling with gcc, with Visual Studio however I receive the following error message:

[libprotobuf WARNING ...\protobuf-cpp-3.21.9__\protobuf-3.21.9\src\google\protobuf\text_format.cc:2157] Can't print proto content: proto type type.googleapis.com/MessageType not found

This is the code I run:

google::protobuf::Any msg;
msg.ParseFromArray(msg_ptr, msg_size);

std::cout << msg.DebugString() << std::endl;

// parseFromArray<MessageType>( msg_ptr, msg_size ); <-- This is not needed when compiling with gcc

with

template<typename M>
static M parseFromArray( const void* msg, size_t size )
{
    M result;

    google::protobuf::Any any;
    any.ParseFromArray( msg, static_cast<int>( size ) );
    return parseFromAny<M>( any );
}

So, with Visual Studio I have to parse the any message to the actual received type at least once and somewhere (note, that 'parseFromArray' is called AFTER DebugString()).

Any ideas/suggestions what to try here?

Thanks in advance!

Tested with
 - Protobuf 3.11.2 and 3.21.9
 - Visual Studio 2022
 - Ubuntu 22 with gcc
Reply all
Reply to author
Forward
0 new messages