deskflow/src/lib/io/StreamBuffer.h

70 lines
1.4 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
2012-06-10 16:50:54 +00:00
*/
#pragma once
2012-06-10 16:50:54 +00:00
#include "base/EventTypes.h"
#include "common/StdList.h"
#include "common/StdVector.h"
2012-06-10 16:50:54 +00:00
//! FIFO of bytes
/*!
This class maintains a FIFO (first-in, last-out) buffer of bytes.
*/
class StreamBuffer
{
2012-06-10 16:50:54 +00:00
public:
StreamBuffer();
~StreamBuffer();
2012-06-10 16:50:54 +00:00
//! @name manipulators
//@{
2012-06-10 16:50:54 +00:00
//! Read data without removing from buffer
/*!
Return a pointer to memory with the next \c n bytes in the buffer
(which must be <= getSize()). The caller must not modify the returned
memory nor delete it.
*/
2025-01-11 02:13:19 +00:00
const void *peek(uint32_t n);
2012-06-10 16:50:54 +00:00
//! Discard data
/*!
Discards the next \c n bytes. If \c n >= getSize() then the buffer
is cleared.
*/
2025-01-11 02:13:19 +00:00
void pop(uint32_t n);
2012-06-10 16:50:54 +00:00
//! Write data to buffer
/*!
Appends \c n bytes from \c data to the buffer.
*/
2025-01-11 02:13:19 +00:00
void write(const void *data, uint32_t n);
2012-06-10 16:50:54 +00:00
//@}
//! @name accessors
//@{
2012-06-10 16:50:54 +00:00
//! Get size of buffer
/*!
Returns the number of bytes in the buffer.
*/
2025-01-11 02:13:19 +00:00
uint32_t getSize() const;
2012-06-10 16:50:54 +00:00
//@}
2012-06-10 16:50:54 +00:00
private:
2025-01-11 02:13:19 +00:00
static const uint32_t kChunkSize;
2012-06-10 16:50:54 +00:00
2025-01-11 00:09:43 +00:00
using Chunk = std::vector<uint8_t>;
using ChunkList = std::list<Chunk>;
2012-06-10 16:50:54 +00:00
ChunkList m_chunks;
2025-01-11 02:13:19 +00:00
uint32_t m_size;
uint32_t m_headUsed;
2012-06-10 16:50:54 +00:00
};