Convert the given double to a JSON string, which is either the number, "NaN" or "Infinity" or "-Infinity".
| 537 | // Convert the given double to a JSON string, which is either the number, |
| 538 | // "NaN" or "Infinity" or "-Infinity". |
| 539 | uint32_t TJSONProtocol::writeJSONDouble(double num) { |
| 540 | uint32_t result = context_->write(*trans_); |
| 541 | std::string val; |
| 542 | |
| 543 | bool special = false; |
| 544 | switch (std::fpclassify(num)) { |
| 545 | case FP_INFINITE: |
| 546 | if (std::signbit(num)) { |
| 547 | val = kThriftNegativeInfinity; |
| 548 | } else { |
| 549 | val = kThriftInfinity; |
| 550 | } |
| 551 | special = true; |
| 552 | break; |
| 553 | case FP_NAN: |
| 554 | val = kThriftNan; |
| 555 | special = true; |
| 556 | break; |
| 557 | default: |
| 558 | val = doubleToString(num); |
| 559 | break; |
| 560 | } |
| 561 | |
| 562 | bool escapeNum = special || context_->escapeNum(); |
| 563 | if (escapeNum) { |
| 564 | trans_->write(&kJSONStringDelimiter, 1); |
| 565 | result += 1; |
| 566 | } |
| 567 | if (val.length() > (std::numeric_limits<uint32_t>::max)()) |
| 568 | throw TProtocolException(TProtocolException::SIZE_LIMIT); |
| 569 | trans_->write((const uint8_t*)val.c_str(), static_cast<uint32_t>(val.length())); |
| 570 | result += static_cast<uint32_t>(val.length()); |
| 571 | if (escapeNum) { |
| 572 | trans_->write(&kJSONStringDelimiter, 1); |
| 573 | result += 1; |
| 574 | } |
| 575 | return result; |
| 576 | } |
| 577 | |
| 578 | uint32_t TJSONProtocol::writeJSONObjectStart() { |
| 579 | uint32_t result = context_->write(*trans_); |
nothing calls this directly
no test coverage detected