question

Upvotes
Accepted
185 6 12 26

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?
#technologyrfac++
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.

Hello @mktdata

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?


If so please can you click the 'Accept' text next to the appropriate reply? This will guide all community members who have a similar question.

Thanks,


AHS

@mktdata

Hi,

Please be informed that a reply has been verified as correct in answering the question, and marked as such.

Thanks,

AHS

1 Answer

· Write an Answer
Upvotes
Accepted
79.2k 251 52 74

@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.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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