C++驱动程序中 Blob 类型的映射

Mapping of Blob type in C++Driver

本文关键字:映射 类型 Blob 驱动程序 C++      更新时间:2023-10-16

根据"datastax.github.io/cpp-driver/topics/basics/",Cassandra 的 blob 数据类型与 'const cass_byte_t*' 匹配。 假设数据库包含以 blob 形式保存的结构;我怎么能取它。有人建议我使用 cass_value_get_bytes((。 任何人都可以举例说明如何使用此函数来获取结构吗?

cass_value_get_bytes()有什么问题?您只需要对读取到结构的数据进行强制转换,如下所示:

const cass_byte_t* outPtr = null;
size_t outSize = 0;
if (cass_value_get_bytes(casValue, &outPtr, &outSize) == CASS_OK) {
   if (outSize == sizeof(YourStruct)) {
       const YourStruct* yourStruct = reinterpret_cast<const YourStruct*>(outPtr);
   }
}