|
|
@ -1,10 +1,44 @@ |
|
|
|
#include "util/serialize_value.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
#include "util/coding.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace leveldb{ |
|
|
|
std::string SerializeValue(const FieldArray& fields){ |
|
|
|
return ""; |
|
|
|
bool compareByFirst(const Field& a, const Field& b) { |
|
|
|
return a.first < b.first; // 按字段名升序排序
|
|
|
|
} |
|
|
|
|
|
|
|
std::string SerializeValue(const FieldArray& fields){ |
|
|
|
FieldArray sortFields = fields; |
|
|
|
std::sort(sortFields.begin(), sortFields.end(), compareByFirst); |
|
|
|
std::string result; |
|
|
|
for (const Field& pairs : sortFields) { |
|
|
|
PutLengthPrefixedSlice(&result, pairs.first); |
|
|
|
PutLengthPrefixedSlice(&result, pairs.second); |
|
|
|
} |
|
|
|
FieldArray *ParseValue(const std::string& value_str){ |
|
|
|
return new FieldArray; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
FieldArray *ParseValue(const std::string& value_str){ |
|
|
|
Slice valueSlice(value_str); |
|
|
|
FieldArray *res = new FieldArray; |
|
|
|
Slice nameSlice = Slice(); |
|
|
|
Slice valSlice = Slice(); |
|
|
|
std::string nameStr; |
|
|
|
std::string valStr; |
|
|
|
while(GetLengthPrefixedSlice(&valueSlice, &nameSlice)){ |
|
|
|
nameStr = nameSlice.ToString(); |
|
|
|
|
|
|
|
if(GetLengthPrefixedSlice(&valueSlice, &valSlice)){ |
|
|
|
valStr = valSlice.ToString(); |
|
|
|
res->emplace_back(nameStr, valStr); |
|
|
|
} else { |
|
|
|
std::cout << "name and val not match!" << std::endl; |
|
|
|
} |
|
|
|
nameSlice = Slice(); |
|
|
|
valSlice = Slice(); |
|
|
|
} |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |