question

Upvotes
Accepted
10 2 6 9

Get double as integer

For example I have Real32 DataBuffer. If I call getInt64,what will happen? Truncate or error?

If a Real64/Double DataBuffer, I also call getInt64(). What will happen?

#technologyrfa-apic++
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.

Integer type of DataBuffer but getAsDouble(), what will happen. Basically my application's receiving variable can be a different type. For example I could getDouble() then cast the value into integer. Just want to explore whether I can call getInt64() directly. Same for all Integral DataBuffer, may I call getDouble()?

@ming.cheng

According to the question, it looks like you are developing a new application with RFA C++.

RFA C++ is a legacy API and we don't recommend developing a new application with the legacy API.

If you are developing a new application to consume real-time data, please consider using the RTSDK C/C++ (EMA C++) instead. Please also refer to the API Compatibility Matrix for the support operating systems and compilers.

I am adding new feature to existing program. Thanks for reminding.
Upvotes
Accepted
78.8k 250 52 74

@ming.cheng

I checked and found that DataBuffer::getDouble() works with Real and Double. Otherwise, you will get the following exception.

Invalid DataBuffer type [4] in DataBuffer::getDouble(). Only RealEnum or DoubleEnum types are allowed.

I can call getInt() for Real but I only get the integer part.

case DataBuffer::RealEnum:
   _out->out("\n GetInt for Real: %lld\n", dataBuffer.getInt());
   _out->out("\n GetDouble for Real: %f\n", dataBuffer.getDouble());
   printf("\nGetAsString(): %s\n", dataBuffer.getAsString().c_str());
break;


GetInt for Real: 3
GetDouble for Real: 3.720099
GetAsString(): 3.720099
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.

Upvotes
78.8k 250 52 74

@ming.cheng

Thanks for reaching out to us.

I checked the document and found that "The getInt64 method has been [DEPRECATED]. The setInt and getInt methods provide a simpler interface and can be used to replace the setInt64 and getInt64 methods."

However, the document states that it can throw InvalidUsageException when Illegal DataBuffer Type found.

I recommended checking the type before calling associated methods.

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.

Upvotes
10 2 6 9

So when come to type handling, must be apple to apple, pear to pear. Otherwise user will get InvalidUsageException error. If necessary, user should convert a value to another type by user code.

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.

Upvotes
10 2 6 9

but for Real64Enum/Real32Enum databuffer, user can still use getDouble() as normal double value?

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.