| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/spdy/spdy_buffer.h" | |
| 6 | |
| 7 #include <cstring> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "net/base/io_buffer.h" | |
| 11 #include "net/spdy/spdy_protocol.h" | |
| 12 | |
| 13 namespace net { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // Makes a SpdyFrame with |size| bytes of data copied from | |
| 18 // |data|. |data| must be non-NULL and |size| must be positive. | |
| 19 scoped_ptr<SpdyFrame> MakeSpdyFrame(const char* data, size_t size) { | |
| 20 DCHECK(data); | |
| 21 DCHECK_GT(size, 0u); | |
| 22 scoped_array<char> frame_data(new char[size]); | |
| 23 std::memcpy(frame_data.get(), data, size); | |
| 24 scoped_ptr<SpdyFrame> frame( | |
| 25 new SpdyFrame(frame_data.release(), size, true /* owns_buffer */)); | |
| 26 return frame.Pass(); | |
| 27 } | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 SpdyBuffer::SpdyBuffer(scoped_ptr<SpdyFrame> frame) | |
| 32 : frame_(frame.Pass()), | |
| 33 offset_(0) {} | |
| 34 | |
| 35 // The given data may not be strictly a SPDY frame; we (ab)use | |
| 36 // |frame_| just as a container. | |
| 37 SpdyBuffer::SpdyBuffer(const char* data, size_t size) : | |
| 38 frame_(MakeSpdyFrame(data, size)), | |
| 39 offset_(0) {} | |
| 40 | |
| 41 SpdyBuffer::~SpdyBuffer() {} | |
| 42 | |
| 43 const char* SpdyBuffer::GetRemainingData() const { | |
| 44 return frame_->data() + offset_; | |
| 45 } | |
| 46 | |
| 47 size_t SpdyBuffer::GetRemainingSize() const { | |
| 48 return frame_->size() - offset_; | |
| 49 } | |
| 50 | |
| 51 void SpdyBuffer::Consume(size_t consume_size) { | |
| 52 DCHECK_GE(consume_size, 1u); | |
| 53 DCHECK_LE(consume_size, GetRemainingSize()); | |
| 54 offset_ += consume_size; | |
| 55 }; | |
| 56 | |
| 57 IOBuffer* SpdyBuffer::GetIOBufferForRemainingData() { | |
| 58 return new WrappedIOBuffer(GetRemainingData()); | |
| 59 } | |
| 60 | |
| 61 } // namespace net | |
| OLD | NEW |