This source file includes following definitions.
- suffix_length_
- Available
- ReadN
- ReadN
#include "net/spdy/spdy_prefixed_buffer_reader.h"
#include "base/logging.h"
namespace net {
SpdyPrefixedBufferReader::SpdyPrefixedBufferReader(
const char* prefix,
size_t prefix_length,
const char* suffix,
size_t suffix_length)
: prefix_(prefix),
suffix_(suffix),
prefix_length_(prefix_length),
suffix_length_(suffix_length) {}
size_t SpdyPrefixedBufferReader::Available() {
return prefix_length_ + suffix_length_;
}
bool SpdyPrefixedBufferReader::ReadN(size_t count, char* out) {
if (Available() < count)
return false;
if (prefix_length_ >= count) {
std::copy(prefix_, prefix_ + count, out);
prefix_ += count;
prefix_length_ -= count;
return true;
} else if (prefix_length_ != 0) {
out = std::copy(prefix_, prefix_ + prefix_length_, out);
count -= prefix_length_;
prefix_length_ = 0;
}
DCHECK(suffix_length_ >= count);
std::copy(suffix_, suffix_ + count, out);
suffix_ += count;
suffix_length_ -= count;
return true;
}
bool SpdyPrefixedBufferReader::ReadN(size_t count,
SpdyPinnableBufferPiece* out) {
if (Available() < count)
return false;
out->storage_.reset();
out->length_ = count;
if (prefix_length_ >= count) {
out->buffer_ = prefix_;
prefix_ += count;
prefix_length_ -= count;
return true;
} else if (prefix_length_ != 0) {
out->storage_.reset(new char[count]);
out->buffer_ = out->storage_.get();
ReadN(count, out->storage_.get());
return true;
} else {
DCHECK(suffix_length_ >= count);
out->buffer_ = suffix_;
suffix_ += count;
suffix_length_ -= count;
return true;
}
}
}