2 #include "base64vlq.hpp"
6 std::string Base64VLQ::encode(const int number) const
8 std::string encoded = "";
10 int vlq = to_vlq_signed(number);
13 int digit = vlq & VLQ_BASE_MASK;
14 vlq >>= VLQ_BASE_SHIFT;
16 digit |= VLQ_CONTINUATION_BIT;
18 encoded += base64_encode(digit);
24 char Base64VLQ::base64_encode(const int number) const
27 if (index < 0) index = 0;
28 if (index > 63) index = 63;
29 return CHARACTERS[index];
32 int Base64VLQ::to_vlq_signed(const int number) const
34 return (number < 0) ? ((-number) << 1) + 1 : (number << 1) + 0;
37 const char* Base64VLQ::CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
39 const int Base64VLQ::VLQ_BASE_SHIFT = 5;
40 const int Base64VLQ::VLQ_BASE = 1 << VLQ_BASE_SHIFT;
41 const int Base64VLQ::VLQ_BASE_MASK = VLQ_BASE - 1;
42 const int Base64VLQ::VLQ_CONTINUATION_BIT = VLQ_BASE;