MCPcopy Create free account
hub / github.com/bytedance/terarkdb / EncodeJSONPrimitive

Function EncodeJSONPrimitive

utilities/document/document_db.cc:302–332  ·  view source on GitHub ↗

encodes simple JSON members (meaning string, integer, etc) the end result of this will be lexicographically compared to each other

Source from the content-addressed store, hash-verified

300// encodes simple JSON members (meaning string, integer, etc)
301// the end result of this will be lexicographically compared to each other
302bool EncodeJSONPrimitive(const JSONDocument& json, std::string* dst) {
303 // TODO(icanadi) revise this at some point, have a custom comparator
304 switch (json.type()) {
305 case JSONDocument::kNull:
306 dst->push_back(kNull);
307 break;
308 case JSONDocument::kBool:
309 dst->push_back(kBool);
310 dst->push_back(static_cast<char>(json.GetBool()));
311 break;
312 case JSONDocument::kDouble:
313 dst->push_back(kDouble);
314 PutFixed64(dst, static_cast<uint64_t>(json.GetDouble()));
315 break;
316 case JSONDocument::kInt64:
317 dst->push_back(kInt64);
318 {
319 auto val = json.GetInt64();
320 dst->push_back((val < 0) ? '0' : '1');
321 PutFixed64(dst, static_cast<uint64_t>(val));
322 }
323 break;
324 case JSONDocument::kString:
325 dst->push_back(kString);
326 dst->append(json.GetString());
327 break;
328 default:
329 return false;
330 }
331 return true;
332}
333
334} // namespace
335

Callers 6

GetIndexKeyMethod · 0.85
PositionMethod · 0.85
ShouldContinueLookingMethod · 0.85
InsertMethod · 0.85
RemoveMethod · 0.85
UpdateMethod · 0.85

Calls 8

PutFixed64Function · 0.85
push_backMethod · 0.80
GetBoolMethod · 0.80
GetDoubleMethod · 0.80
GetInt64Method · 0.80
typeMethod · 0.45
appendMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected