一个基于Key/Value方式存取二进制数据的接口设计

  • 支持对单个条目进行加密
  • 增删改查方法
  • 辅助方法
  • 能够使用以下5种方式进行序列化
    • "SQLITE" Sqlite数据库
    • "XML" XML文件
    • "INI" INI文件
    • "DIR" 文件系统(目录结构)
    • "REG" Windows注册表
  • 支持拷贝
  • 完整的错误处理
  • 支持尽可能多的STL容器类型作为buf
  • 线程安全(可选)

要求能通过不低于此测试用例强度的单元测试:http://git.koal.com/chenlei/blobstore/blob/master/blobstore/blobstore_test.cc

BlobStore 使用范例(C++伪代码)


XMLBlobStore xml_store("/path/to/xml");

char in_buf1[] = "11111111111111111111111111";
std::string in_buf2 = "222222222222222222222222";
std::vector<char> in_buf3(in_buf1, in_buf1 + sizeof(in_buf1));

// 设置明文
xml_store.setBlob("testkey1", in_buf1, sizeof(in_buf1));
xml_store.setBlob("testkey2", in_buf2);
xml_store.setBlob("testkey3", in_buf3)
// 以明文方式取出
char out_buf1[MAX];
std::string out_buf2;
std::vector<char> outbuf2;
xml_store.getBlob("testkey1", out_buf1, sizeof(out_buf1));
xml_store.getBlob("testkey2", out_buf2);
xml_store.getBlob("testkey2", out_buf3);

// 设置密文
xml_store.setEncryptedBlob("testkey1", passwd, in_buf1, sizeof(in_buf1));
xml_store.setBlob("testkey2", passwd, in_buf2, in_buf2.size());
// 以密文方式取出
char out_buf1[MAX];
std::string out_buf2;
xml_store.getBlob("testkey1", passwd, out_buf1, sizeof(out_buf1));
xml_store.getBlob("testkey2", passwd, out_buf2);

// 辅助方法
std::vector<std::string> keys = xml_store.keys();
bool has_key = xml_store.hasKey("testkey1");
bool is_encryped = xml_store.isEncrypted("testkey1");

// 序列化
xml_store.load(); // 从XML文件加载
xml_store.save(); // 序列化到XML文件

// 拷贝
XMLBlobStore new_xml_store("/path/to/new/xml");
blobstore_copy(new_xml_store, xml_store);
new_xml_store.save();

DBBlobStore db_store("/path/to/db");
blobstore_copy(db_store, xml_store);

相关文章: