Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
buffer.h File Reference
#include <inttypes.h>
#include <stddef.h>
#include "ws_symbol_export.h"

Go to the source code of this file.

Classes

struct  Buffer
 A dynamic byte buffer with adjustable start and end positions. More...
 

Macros

#define SOME_FUNCTIONS_ARE_INLINE
 
#define DEFAULT_INIT_BUFFER_SIZE_2048   (2 * 1024) /* Everyone still uses 1500 byte frames, right? */
 

Typedefs

typedef struct Buffer Buffer
 A dynamic byte buffer with adjustable start and end positions.
 

Functions

WS_DLL_PUBLIC void ws_buffer_init (Buffer *buffer, size_t space)
 Initializes a Buffer with the specified initial capacity.
 
WS_DLL_PUBLIC void ws_buffer_free (Buffer *buffer)
 Frees the memory associated with a Buffer.
 
WS_DLL_PUBLIC void ws_buffer_assure_space (Buffer *buffer, size_t space)
 Ensures the buffer has enough space for additional data.
 
WS_DLL_PUBLIC void ws_buffer_append (Buffer *buffer, const uint8_t *from, size_t bytes)
 Appends data to the end of the buffer.
 
WS_DLL_PUBLIC void ws_buffer_remove_start (Buffer *buffer, size_t bytes)
 Removes bytes from the beginning of the buffer.
 
WS_DLL_PUBLIC void ws_buffer_cleanup (void)
 Cleans up internal buffer state across all active buffers.
 

Detailed Description

Wiretap Library Copyright (c) 1998 by Gilbert Ramirez gram@.nosp@m.alum.nosp@m.ni.ri.nosp@m.ce.e.nosp@m.du

SPDX-License-Identifier: GPL-2.0-or-later

Typedef Documentation

◆ Buffer

typedef struct Buffer Buffer

A dynamic byte buffer with adjustable start and end positions.

This structure supports efficient appending and trimming of data, making it suitable for streaming or incremental parsing scenarios.

Function Documentation

◆ ws_buffer_append()

WS_DLL_PUBLIC void ws_buffer_append ( Buffer buffer,
const uint8_t *  from,
size_t  bytes 
)

Appends data to the end of the buffer.

Copies bytes from from into the buffer starting at first_free, expanding the buffer if needed.

Parameters
bufferPointer to the Buffer structure.
fromPointer to the source data.
bytesNumber of bytes to append.

◆ ws_buffer_assure_space()

WS_DLL_PUBLIC void ws_buffer_assure_space ( Buffer buffer,
size_t  space 
)

Ensures the buffer has enough space for additional data.

Expands the buffer if necessary to accommodate space bytes beyond first_free.

Parameters
bufferPointer to the Buffer structure.
spaceNumber of additional bytes required.

◆ ws_buffer_cleanup()

WS_DLL_PUBLIC void ws_buffer_cleanup ( void  )

Cleans up internal buffer state across all active buffers.

Performs global cleanup tasks, such as releasing shared resources or resetting internal buffer tracking. Typically called during shutdown.

◆ ws_buffer_free()

WS_DLL_PUBLIC void ws_buffer_free ( Buffer buffer)

Frees the memory associated with a Buffer.

Releases any allocated memory and resets internal fields.

Parameters
bufferPointer to the Buffer structure to free.

◆ ws_buffer_init()

WS_DLL_PUBLIC void ws_buffer_init ( Buffer buffer,
size_t  space 
)

Initializes a Buffer with the specified initial capacity.

Allocates memory for the buffer and sets internal pointers.

Parameters
bufferPointer to the Buffer structure to initialize.
spaceInitial size of the buffer in bytes.

◆ ws_buffer_remove_start()

WS_DLL_PUBLIC void ws_buffer_remove_start ( Buffer buffer,
size_t  bytes 
)

Removes bytes from the beginning of the buffer.

Advances the start pointer by bytes, effectively discarding that portion. Does not shrink the allocated memory.

Parameters
bufferPointer to the Buffer structure.
bytesNumber of bytes to remove from the start.

ws_error() does an abort() and thus never returns