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

瀏覽次數:293 次
跳到第一則未讀訊息

Andreas Folkers

未讀,
2022年11月18日 凌晨4:40:372022/11/18
收件者: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
回覆所有人
回覆作者
轉寄
0 則新訊息