2021-11-25 22:31:05 -05:00
|
|
|
/** @file
|
2014-01-01 13:18:45 +00:00
|
|
|
*
|
|
|
|
* Wiretap Library
|
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
|
|
|
*
|
2018-02-07 12:26:45 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2014-01-01 13:18:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __W_BUFFER_H__
|
|
|
|
#define __W_BUFFER_H__
|
|
|
|
|
2023-09-22 13:42:49 -07:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stddef.h>
|
2014-01-01 13:18:45 +00:00
|
|
|
#include "ws_symbol_export.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2025-01-01 19:35:17 -08:00
|
|
|
#define SOME_FUNCTIONS_ARE_INLINE
|
2014-01-01 13:18:45 +00:00
|
|
|
|
|
|
|
typedef struct Buffer {
|
2023-09-22 13:42:49 -07:00
|
|
|
uint8_t *data;
|
|
|
|
size_t allocated;
|
|
|
|
size_t start;
|
|
|
|
size_t first_free;
|
2014-01-01 13:18:45 +00:00
|
|
|
} Buffer;
|
|
|
|
|
|
|
|
WS_DLL_PUBLIC
|
2023-09-22 13:42:49 -07:00
|
|
|
void ws_buffer_init(Buffer* buffer, size_t space);
|
2014-01-01 13:18:45 +00:00
|
|
|
WS_DLL_PUBLIC
|
2014-08-02 04:00:48 -07:00
|
|
|
void ws_buffer_free(Buffer* buffer);
|
2014-01-01 13:18:45 +00:00
|
|
|
WS_DLL_PUBLIC
|
2023-09-22 13:42:49 -07:00
|
|
|
void ws_buffer_assure_space(Buffer* buffer, size_t space);
|
2014-01-01 13:18:45 +00:00
|
|
|
WS_DLL_PUBLIC
|
2024-12-29 16:38:31 -08:00
|
|
|
void ws_buffer_append(Buffer* buffer, const uint8_t *from, size_t bytes);
|
2014-01-01 13:18:45 +00:00
|
|
|
WS_DLL_PUBLIC
|
2023-09-22 13:42:49 -07:00
|
|
|
void ws_buffer_remove_start(Buffer* buffer, size_t bytes);
|
2017-02-04 16:26:34 +01:00
|
|
|
WS_DLL_PUBLIC
|
|
|
|
void ws_buffer_cleanup(void);
|
2014-01-01 13:18:45 +00:00
|
|
|
|
2025-01-01 19:35:17 -08:00
|
|
|
#ifdef SOME_FUNCTIONS_ARE_INLINE
|
2025-01-01 18:26:06 -08:00
|
|
|
/* Or inlines */
|
|
|
|
static inline void
|
|
|
|
ws_buffer_clean(Buffer *buffer)
|
|
|
|
{
|
|
|
|
buffer->start = 0;
|
|
|
|
buffer->first_free = 0;
|
|
|
|
}
|
2025-01-01 19:35:17 -08:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
ws_buffer_increase_length(Buffer* buffer, size_t bytes)
|
|
|
|
{
|
|
|
|
buffer->first_free += bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t
|
2025-01-02 01:30:27 -08:00
|
|
|
ws_buffer_length(const Buffer* buffer)
|
2025-01-01 19:35:17 -08:00
|
|
|
{
|
|
|
|
return buffer->first_free - buffer->start;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t *
|
2025-01-02 01:30:27 -08:00
|
|
|
ws_buffer_start_ptr(const Buffer* buffer)
|
2025-01-01 19:35:17 -08:00
|
|
|
{
|
|
|
|
return buffer->data + buffer->start;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t *
|
2025-01-02 01:30:27 -08:00
|
|
|
ws_buffer_end_ptr(const Buffer* buffer)
|
2025-01-01 19:35:17 -08:00
|
|
|
{
|
|
|
|
return buffer->data + buffer->first_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
ws_buffer_append_buffer(Buffer* buffer, Buffer* src_buffer)
|
|
|
|
{
|
|
|
|
ws_buffer_append(buffer, ws_buffer_start_ptr(src_buffer), ws_buffer_length(src_buffer));
|
|
|
|
}
|
2014-01-01 13:18:45 +00:00
|
|
|
#else
|
2023-02-07 19:52:37 +00:00
|
|
|
WS_DLL_PUBLIC
|
2014-08-02 04:00:48 -07:00
|
|
|
void ws_buffer_clean(Buffer* buffer);
|
2023-02-07 19:52:37 +00:00
|
|
|
WS_DLL_PUBLIC
|
2023-09-22 13:42:49 -07:00
|
|
|
void ws_buffer_increase_length(Buffer* buffer, size_t bytes);
|
2023-02-07 19:52:37 +00:00
|
|
|
WS_DLL_PUBLIC
|
2025-01-02 01:30:27 -08:00
|
|
|
size_t ws_buffer_length(const Buffer* buffer);
|
2023-02-07 19:52:37 +00:00
|
|
|
WS_DLL_PUBLIC
|
2025-01-02 01:30:27 -08:00
|
|
|
uint8_t* ws_buffer_start_ptr(const Buffer* buffer);
|
2023-02-07 19:52:37 +00:00
|
|
|
WS_DLL_PUBLIC
|
2025-01-02 01:30:27 -08:00
|
|
|
uint8_t* ws_buffer_end_ptr(const Buffer* buffer);
|
2023-02-07 19:52:37 +00:00
|
|
|
WS_DLL_PUBLIC
|
2014-08-02 04:00:48 -07:00
|
|
|
void ws_buffer_append_buffer(Buffer* buffer, Buffer* src_buffer);
|
2014-01-01 13:18:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
#endif
|