MCPcopy Create free account
hub / github.com/apple/foundationdb / encode

Function encode

fdbrpc/Base64UrlEncode.cpp:30–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30int encode(const uint8_t* __restrict plaintextIn, int lengthIn, uint8_t* __restrict codeOut) noexcept {
31 const uint8_t* plainchar = plaintextIn;
32 const uint8_t* const plaintextEnd = plaintextIn + lengthIn;
33 uint8_t* codechar = codeOut;
34 uint8_t result = 0;
35 uint8_t fragment = 0;
36
37 while (1) {
38 if (plainchar == plaintextEnd) {
39 return codechar - codeOut;
40 }
41 // byte 1 of 3
42 fragment = *plainchar++;
43 result = (fragment & 0x0fc) >> 2;
44 *codechar++ = encodeValue(result);
45 result = (fragment & 0x003) << 4;
46 if (plainchar == plaintextEnd) {
47 *codechar++ = encodeValue(result);
48 return codechar - codeOut;
49 }
50 // byte 2 of 3
51 fragment = *plainchar++;
52 result |= (fragment & 0x0f0) >> 4;
53 *codechar++ = encodeValue(result);
54 result = (fragment & 0x00f) << 2;
55 if (plainchar == plaintextEnd) {
56 *codechar++ = encodeValue(result);
57 return codechar - codeOut;
58 }
59 // byte 3 of 3
60 fragment = *plainchar++;
61 result |= (fragment & 0x0c0) >> 6;
62 *codechar++ = encodeValue(result);
63 result = (fragment & 0x03f) >> 0;
64 *codechar++ = encodeValue(result);
65 }
66 /* control should not reach here */
67 return codechar - codeOut;
68}
69
70int encodedLength(int dataLength) noexcept {
71 auto r = dataLength % 3;

Callers 7

bigNumToBase64UrlFunction · 0.70
makeTokenPartFunction · 0.70
signTokenFunction · 0.70
encodeMethod · 0.50
encodeMethod · 0.50
packMethod · 0.50

Calls 5

encodedLengthFunction · 0.85
encodeValueFunction · 0.70
StringRefClass · 0.50
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected