|
#include "util/coding.h"
|
|
#include "db/vlog_converter.h"
|
|
namespace leveldb{
|
|
namespace vlog{
|
|
// 当需要将键值对插入数据库时,将值的存储位置 (file_no 和 file_offset) 编码为 Vlog Pointer,并与键关联存储。
|
|
// 紧凑的编码格式便于减少存储开销。
|
|
Slice VlogConverter::GetVptr(uint64_t file_no, uint64_t file_offset, char* buf){
|
|
char* vfileno_end = EncodeVarint64(buf, file_no);
|
|
char* vfileoff_end = EncodeVarint64(vfileno_end, file_offset);
|
|
return Slice(buf, vfileoff_end - buf);
|
|
}
|
|
Status VlogConverter::DecodeVptr(uint64_t* file_no, uint64_t* file_offset, Slice* vptr){
|
|
bool decoded_status = true;
|
|
decoded_status &= GetVarint64(vptr, file_no);
|
|
decoded_status &= GetVarint64(vptr, file_offset);
|
|
if(!decoded_status) return Status::Corruption("Can not Decode vptr from Read Bytes.");
|
|
else return Status::OK();
|
|
}
|
|
}// namespace vlog
|
|
}
|