小组成员: 曹可心-10223903406 朴祉燕-10224602413
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

26 lines
811 B

#include <cstdint>
#include "db/vlog_writer.h"
#include "leveldb/slice.h"
#include "leveldb/env.h"
#include "util/coding.h"
namespace leveldb{
namespace vlog{
VWriter::VWriter(WritableFile* vlogfile)
:vlogfile_(vlogfile){}
VWriter::~VWriter() = default;
Status VWriter::AddRecord(const Slice& slice, int& write_size){
//append slice length.
write_size = slice.size();
char buf[10]; // Used for Convert int64 to char.
char* end_byte = EncodeVarint64(buf, slice.size());
write_size += end_byte - buf;
Status s = vlogfile_->Append(Slice(buf, end_byte - buf));
//append slice
if(s.ok()) s = vlogfile_->Append(slice);
return s;
}
Status VWriter::Flush(){
return vlogfile_->Flush();
}
}// namespace vlog
}