| 531 | } |
| 532 | |
| 533 | void write_bignum(bigint& n) |
| 534 | { |
| 535 | bool is_neg = n < 0; |
| 536 | if (is_neg) |
| 537 | { |
| 538 | n = - n -1; |
| 539 | } |
| 540 | |
| 541 | int signum; |
| 542 | std::vector<uint8_t> data; |
| 543 | n.write_bytes_be(signum, data); |
| 544 | std::size_t length = data.size(); |
| 545 | |
| 546 | if (is_neg) |
| 547 | { |
| 548 | write_tag(3); |
| 549 | } |
| 550 | else |
| 551 | { |
| 552 | write_tag(2); |
| 553 | } |
| 554 | |
| 555 | if (length <= 0x17) |
| 556 | { |
| 557 | // fixstr stores a byte array whose length is upto 31 bytes |
| 558 | binary::native_to_big(static_cast<uint8_t>(0x40 + length), |
| 559 | std::back_inserter(sink_)); |
| 560 | } |
| 561 | else if (length <= 0xff) |
| 562 | { |
| 563 | binary::native_to_big(static_cast<uint8_t>(0x58), |
| 564 | std::back_inserter(sink_)); |
| 565 | binary::native_to_big(static_cast<uint8_t>(length), |
| 566 | std::back_inserter(sink_)); |
| 567 | } |
| 568 | else if (length <= 0xffff) |
| 569 | { |
| 570 | binary::native_to_big(static_cast<uint8_t>(0x59), |
| 571 | std::back_inserter(sink_)); |
| 572 | binary::native_to_big(static_cast<uint16_t>(length), |
| 573 | std::back_inserter(sink_)); |
| 574 | } |
| 575 | else if (length <= 0xffffffff) |
| 576 | { |
| 577 | binary::native_to_big(static_cast<uint8_t>(0x5a), |
| 578 | std::back_inserter(sink_)); |
| 579 | binary::native_to_big(static_cast<uint32_t>(length), |
| 580 | std::back_inserter(sink_)); |
| 581 | } |
| 582 | else if (uint64_t(length) <= (std::numeric_limits<std::uint64_t>::max)()) |
| 583 | { |
| 584 | binary::native_to_big(static_cast<uint8_t>(0x5b), |
| 585 | std::back_inserter(sink_)); |
| 586 | binary::native_to_big(static_cast<uint64_t>(length), |
| 587 | std::back_inserter(sink_)); |
| 588 | } |
| 589 | |
| 590 | for (auto c : data) |
no test coverage detected