MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / encodeBase64

Function encodeBase64

include/engine/base64.hpp:44–69  ·  view source on GitHub ↗

Encodes a chunk of memory to Base64.

Source from the content-addressed store, hash-verified

42
43// Encodes a chunk of memory to Base64.
44inline std::string encodeBase64(const unsigned char *first, std::size_t size)
45{
46 BOOST_ASSERT(size > 0);
47
48 std::string encoded;
49 encoded.reserve(((size + 2) / 3) * 4);
50
51 auto padding = (3 - size % 3) % 3;
52
53 BOOST_ASSERT(padding == 0 || padding == 1 || padding == 2);
54
55 for (auto itr = detail::Base64FromBinary(first); itr != detail::Base64FromBinary(first + size);
56 ++itr)
57 {
58 encoded.push_back(*itr);
59 }
60
61 for (size_t index = 0; index < padding; ++index)
62 {
63 encoded.push_back('=');
64 }
65
66 BOOST_ASSERT(encoded.size() == (size + 2) / 3 * 4);
67
68 return encoded;
69}
70
71// C++11 standard 3.9.1/1: Plain char, signed char, and unsigned char are three distinct types
72

Callers 2

BOOST_AUTO_TEST_CASEFunction · 0.85
encodeBase64BytewiseFunction · 0.85

Calls 4

reserveMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected