]>
git.proxmox.com Git - mirror_qemu.git/blob - include/qemu/buffer.h
e95dfd696ca8393822c0ee349f8ede3ca0e6ea91
4 * Copyright (c) 2015 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 typedef struct Buffer Buffer
;
30 * The Buffer object provides a simple dynamically resizing
31 * array, with separate tracking of capacity and usage. This
32 * is typically useful when buffering I/O or processing data.
45 * @buffer: the buffer object
48 * Optionally attach a name to the buffer, to make it easier
49 * to identify in debug traces.
51 void buffer_init(Buffer
*buffer
, const char *name
, ...)
56 * @buffer: the buffer object
58 * Try to shrink the buffer. Checks current buffer capacity and size
59 * and reduces capacity in case only a fraction of the buffer is
62 void buffer_shrink(Buffer
*buffer
);
66 * @buffer: the buffer object
67 * @len: the minimum required free space
69 * Ensure that the buffer has space allocated for at least
70 * @len bytes. If the current buffer is too small, it will
71 * be reallocated, possibly to a larger size than requested.
73 void buffer_reserve(Buffer
*buffer
, size_t len
);
77 * @buffer: the buffer object
79 * Reset the length of the stored data to zero, but do
80 * not free / reallocate the memory buffer
82 void buffer_reset(Buffer
*buffer
);
86 * @buffer: the buffer object
88 * Reset the length of the stored data to zero and also
89 * free the internal memory buffer
91 void buffer_free(Buffer
*buffer
);
95 * @buffer: the buffer object
96 * @data: the data block to append
97 * @len: the length of @data in bytes
99 * Append the contents of @data to the end of the buffer.
100 * The caller must ensure that the buffer has sufficient
101 * free space for @len bytes, typically by calling the
102 * buffer_reserve() method prior to appending.
104 void buffer_append(Buffer
*buffer
, const void *data
, size_t len
);
108 * @buffer: the buffer object
109 * @len: the number of bytes to skip
111 * Remove @len bytes of data from the head of the buffer.
112 * The internal buffer will not be reallocated, so will
113 * have at least @len bytes of free space after this
116 void buffer_advance(Buffer
*buffer
, size_t len
);
120 * @buffer: the buffer object
122 * Get a pointer to the tail end of the internal buffer
123 * The returned pointer is only valid until the next
124 * call to buffer_reserve().
126 * Returns: the tail of the buffer
128 uint8_t *buffer_end(Buffer
*buffer
);
132 * @buffer: the buffer object
134 * Determine if the buffer contains any current data
136 * Returns: true if the buffer holds data, false otherwise
138 gboolean
buffer_empty(Buffer
*buffer
);
142 * @to: destination buffer object
143 * @from: source buffer object
145 * Moves buffer, without copying data. 'to' buffer must be empty.
146 * 'from' buffer is empty and zero-sized on return.
148 void buffer_move_empty(Buffer
*to
, Buffer
*from
);
152 * @to: destination buffer object
153 * @from: source buffer object
155 * Moves buffer, copying data (unless 'to' buffer happens to be empty).
156 * 'from' buffer is empty and zero-sized on return.
158 void buffer_move(Buffer
*to
, Buffer
*from
);
160 #endif /* QEMU_BUFFER_H */