encodes simple JSON members (meaning string, integer, etc) the end result of this will be lexicographically compared to each other
| 300 | // encodes simple JSON members (meaning string, integer, etc) |
| 301 | // the end result of this will be lexicographically compared to each other |
| 302 | bool 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 |
no test coverage detected