37 template <
typename Func>
43 size_t currentLength =
current.size();
45 while (currentLength != 0) {
47 static_cast<size_t>(currentOut->
length() - offset), currentLength);
52 currentLength -= selected;
54 if (offset == currentOut->
length()) {
56 currentOut = currentOut->
next();
73 template <
size_t BlockSize,
typename Func>
76 size_t internallyBuffered = 0;
81 std::array<uint8_t, BlockSize> blockBuffer = {};
86 auto inputLen = inputRange.
size();
88 if (inputLen + internallyBuffered < BlockSize) {
93 auto numWritten = func(blockBuffer.data(), inputRange.data(), inputLen);
94 DCHECK_EQ(numWritten, 0) <<
"expected buffering. wrote " << numWritten;
96 internallyBuffered += inputLen;
98 }
else if (outputLen < BlockSize) {
102 auto numWritten = func(
106 BlockSize - internallyBuffered);
107 DCHECK_EQ(numWritten, BlockSize)
108 <<
"did not write full block bs=" << BlockSize
109 <<
" wrote=" << numWritten;
112 output.
push(blockBuffer.data(), BlockSize);
115 input.
skip(BlockSize - internallyBuffered);
116 internallyBuffered = 0;
120 auto numSharedBytes =
std::min(outputLen, inputLen + internallyBuffered);
123 auto numBlockBytes = numSharedBytes - (numSharedBytes % BlockSize);
126 auto maxToTake = (numBlockBytes - internallyBuffered) + (BlockSize - 1);
127 auto numToTake =
std::min(inputLen, maxToTake);
129 func(output.
writableData(), inputRange.data(), numToTake);
131 DCHECK_EQ(numWritten, numBlockBytes);
134 input.
skip(numToTake);
135 output.
skip(numWritten);
137 internallyBuffered = (internallyBuffered + numToTake) % BlockSize;
void trimBytes(IOBuf &buf, folly::MutableByteRange trimmed)
constexpr size_type size() const
void push(const uint8_t *buf, size_t len)
void XOR(ByteRange first, MutableByteRange second)
std::size_t length() const
folly::io::RWPrivateCursor transformBufferBlocks(const folly::IOBuf &in, folly::IOBuf &out, Func func)
void transformBuffer(const folly::IOBuf &in, folly::IOBuf &out, Func func)
constexpr detail::First first