question

Upvotes
Accepted
163 3 7 11

Convert RespMsg key to std::string

Hello, we are suing RFA 8.1 C++ api's with MBP domain. We receive "key" in Buffer type. The type of the "Buffer::c_buf()" is "unsigned char *" where as std::string requires "char *". Is using DataBuffer::getAsString" is safe in this case?
rfa#technologyc++
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Upvotes
Accepted
56k 145 45 65

@mktdata

Sorry about the issue that you are facing.

The key primitive type is a buffer, not a string.

It is better to use getBuffer(), as shown in the example code.

        case DataBuffer::BufferEnum:
        {
            const Buffer& buf = dataBuffer.getBuffer();
            sData = new char[buf.size() + 1];


            strncpy( sData, (char*)buf.c_buf(), buf.size() );
            sData[ buf.size() ] = '\0';
            write( "%s", sData );


            delete[] sData;
        }

I hope that this information is of help.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.