Reads a block of base64 characters, decoding it, and returns via str
| 803 | |
| 804 | // Reads a block of base64 characters, decoding it, and returns via str |
| 805 | uint32_t TJSONProtocol::readJSONBase64(std::string& str) { |
| 806 | std::string tmp; |
| 807 | uint32_t result = readJSONString(tmp); |
| 808 | auto* b = (uint8_t*)tmp.c_str(); |
| 809 | if (tmp.length() > (std::numeric_limits<uint32_t>::max)()) |
| 810 | throw TProtocolException(TProtocolException::SIZE_LIMIT); |
| 811 | auto len = static_cast<uint32_t>(tmp.length()); |
| 812 | str.clear(); |
| 813 | // Ignore padding |
| 814 | uint32_t padding_count = 0; |
| 815 | while (len > 0 && b[len - 1] == '=' && padding_count < 2) { |
| 816 | --len; |
| 817 | ++padding_count; |
| 818 | } |
| 819 | while (len >= 4) { |
| 820 | base64_decode(b, 4); |
| 821 | str.append((const char*)b, 3); |
| 822 | b += 4; |
| 823 | len -= 4; |
| 824 | } |
| 825 | // Don't decode if we hit the end or got a single leftover byte (invalid |
| 826 | // base64 but legal for skip of regular string type) |
| 827 | if (len > 1) { |
| 828 | base64_decode(b, len); |
| 829 | str.append((const char*)b, len - 1); |
| 830 | } |
| 831 | return result; |
| 832 | } |
| 833 | |
| 834 | // Reads a sequence of characters, stopping at the first one that is not |
| 835 | // a valid JSON numeric character. |