MCPcopy Create free account
hub / github.com/apache/thrift / readJSONBase64

Method readJSONBase64

lib/cpp/src/thrift/protocol/TJSONProtocol.cpp:805–832  ·  view source on GitHub ↗

Reads a block of base64 characters, decoding it, and returns via str

Source from the content-addressed store, hash-verified

803
804// Reads a block of base64 characters, decoding it, and returns via str
805uint32_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.

Callers 2

test_TJSONProtol_readMethod · 0.95
readBinaryMethod · 0.95

Calls 5

base64_decodeFunction · 0.85
TProtocolExceptionClass · 0.70
lengthMethod · 0.65
clearMethod · 0.65
appendMethod · 0.45

Tested by 1

test_TJSONProtol_readMethod · 0.76