question

Upvotes
Accepted
211 6 17 30

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.

1 Answer

· Write an Answer
Upvotes
Accepted
83.1k 281 53 77

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