1 // Copyright 2014 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.
5 #ifndef COMPONENTS_PAIRING_MESSAGE_BUFFER_H_
6 #define COMPONENTS_PAIRING_MESSAGE_BUFFER_H_
10 #include "base/logging.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
18 namespace pairing_chromeos
{
20 // A MessageBuffer is a simple wrapper around an ordered set of buffers received
21 // from a socket. It keeps track of the amount of unread data, and allows data
22 // to be retreived that was split across buffers in a single chunk.
28 // Returns the number of bytes currently received, but not yet read.
31 // Read |size| bytes into |buffer|. |size| must be smaller than or equal to
32 // the current number of available bytes.
33 void ReadBytes(char* buffer
, int size
);
35 // Add the data from an IOBuffer. A reference to the IOBuffer will be
36 // maintained until it is drained.
37 void AddIOBuffer(scoped_refptr
<net::IOBuffer
> io_buffer
, int size
);
40 // Offset of the next byte to be read from the current IOBuffer.
42 // Total number of bytes in IOBuffers in |pending_data_|, including bytes that
43 // have already been read.
44 int total_buffer_size_
;
45 std::deque
<std::pair
<scoped_refptr
<net::IOBuffer
>, int> > pending_data_
;
47 DISALLOW_COPY_AND_ASSIGN(MessageBuffer
);
50 } // namespace pairing_chromeos
52 #endif // COMPONENTS_PAIRING_MESSAGE_BUFFER_H_