1 Star 0 Fork 0

cyys/cpp-driver

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
request.cpp 2.32 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright (c) DataStax, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "request.hpp"
#include "external.hpp"
using namespace datastax::internal::core;
extern "C" {
CassCustomPayload* cass_custom_payload_new() {
CustomPayload* payload = new CustomPayload();
payload->inc_ref();
return CassCustomPayload::to(payload);
}
void cass_custom_payload_set(CassCustomPayload* payload, const char* name, const cass_byte_t* value,
size_t value_size) {
payload->set(name, SAFE_STRLEN(name), value, value_size);
}
void cass_custom_payload_set_n(CassCustomPayload* payload, const char* name, size_t name_length,
const cass_byte_t* value, size_t value_size) {
payload->set(name, name_length, value, value_size);
}
void cass_custom_payload_remove(CassCustomPayload* payload, const char* name) {
payload->remove(name, SAFE_STRLEN(name));
}
void cass_custom_payload_remove_n(CassCustomPayload* payload, const char* name,
size_t name_length) {
payload->remove(name, name_length);
}
void cass_custom_payload_free(CassCustomPayload* payload) { payload->dec_ref(); }
} // extern "C"
void CustomPayload::set(const char* name, size_t name_length, const uint8_t* value,
size_t value_size) {
Buffer buf(sizeof(uint16_t) + name_length + sizeof(int32_t) + value_size);
size_t pos = buf.encode_string(0, name, static_cast<uint16_t>(name_length));
buf.encode_bytes(pos, reinterpret_cast<const char*>(value), value_size);
items_[String(name, name_length)] = buf;
}
int32_t CustomPayload::encode(BufferVec* bufs) const {
int32_t length = 0;
for (ItemMap::const_iterator i = items_.begin(), end = items_.end(); i != end; ++i) {
const Buffer& buf = i->second;
length += buf.size();
bufs->push_back(buf);
}
return length;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cyys/cpp-driver.git
git@gitee.com:cyys/cpp-driver.git
cyys
cpp-driver
cpp-driver
master

搜索帮助