1 // Copyright 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.
5 #ifndef NET_TOOLS_BALSA_BUFFER_INTERFACE_H__
6 #define NET_TOOLS_BALSA_BUFFER_INTERFACE_H__
10 class BufferInterface
{
13 // Returns the bytes which can be read from the buffer. There is no
14 // guarantee that the bytes are contiguous.
15 virtual int ReadableBytes() const = 0;
18 // returns the size of this buffer
20 // size of this buffer.
21 virtual int BufferSize() const = 0;
24 // returns the number of bytes free in this buffer.
26 // number of bytes free.
27 virtual int BytesFree() const = 0;
30 // Returns true if empty.
34 virtual bool Empty() const = 0;
37 // Returns true if the buffer is full.
38 virtual bool Full() const = 0;
41 // returns the number of characters written.
42 // appends up-to-'size' bytes to the buffer.
44 // bytes - bytes which are read, and copied into the buffer.
45 // size - number of bytes which are read and copied.
46 // this number shall be >= 0.
47 virtual int Write(const char* bytes
, int size
) = 0;
50 // Gets a pointer which can be written to (assigned to).
51 // this pointer (and size) can be used in functions like
52 // recv() or read(), etc.
53 // If *size is zero upon returning from this function, that it
54 // is unsafe to dereference *ptr.
56 // ptr - assigned a pointer to which we can write
57 // size - the amount of data (in bytes) that it is safe to write to ptr.
58 virtual void GetWritablePtr(char **ptr
, int* size
) const = 0;
61 // Gets a pointer which can be read from
62 // this pointer (and size) can be used in functions like
63 // send() or write(), etc.
64 // If *size is zero upon returning from this function, that it
65 // is unsafe to dereference *ptr.
67 // ptr - assigned a pointer from which we may read
68 // size - the amount of data (in bytes) that it is safe to read
69 virtual void GetReadablePtr(char **ptr
, int* size
) const = 0;
72 // Reads bytes out of the buffer, and writes them into 'bytes'.
73 // Returns the number of bytes read.
74 // Consumes bytes from the buffer (possibly, but not necessarily
75 // rendering them free)
77 // bytes - the pointer into which bytes are read from this buffer
79 // size - number of bytes which are read and copied.
80 // this number shall be >= 0.
82 // the number of bytes read from 'bytes'
83 virtual int Read(char* bytes
, int size
) = 0;
86 // removes all data from the buffer
87 virtual void Clear() = 0;
90 // reserves contiguous writable empty space in the buffer of size bytes.
91 // Returns true if the reservation is successful.
92 // If a derive class chooses not to implement reservation, its
93 // implementation should return false.
94 virtual bool Reserve(int size
) = 0;
97 // removes the oldest 'amount_to_consume' characters from this buffer,
99 // amount_to_advance - .. this should be self-explanatory =)
100 // this number shall be >= 0.
101 virtual void AdvanceReadablePtr(int amount_to_advance
) = 0;
104 // Moves the internal pointers around such that the
105 // amount of data specified here is expected to
106 // already be resident (as if it was Written)
108 // amount_to_advance - self explanatory.
109 // this number shall be >= 0.
110 virtual void AdvanceWritablePtr(int amount_to_advance
) = 0;
112 virtual ~BufferInterface() {}
120 #endif // NET_TOOLS_BALSA_BUFFER_INTERFACE__H__