blob: ea579a46ab4af23d58217ab575ab0b55b3e0ab6f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include "chunked_input_stream.h"
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
TChunkedInputStream::TChunkedInputStream(std::vector<TSharedRef> blocks)
: Blocks_(std::move(blocks))
{ }
size_t TChunkedInputStream::DoNext(const void** ptr, size_t len)
{
SkipCompletedBlocks();
if (Index_ == Blocks_.size()) {
*ptr = nullptr;
return 0;
}
*ptr = Blocks_[Index_].Begin() + Position_;
size_t toSkip = std::min(Blocks_[Index_].Size() - Position_, len);
Position_ += toSkip;
return toSkip;
}
void TChunkedInputStream::SkipCompletedBlocks()
{
while (Index_ < Blocks_.size() && Position_ == Blocks_[Index_].Size()) {
Index_ += 1;
Position_ = 0;
}
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
|