Wireshark 4.5.0
The Wireshark network protocol analyzer
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
buffer.h
Go to the documentation of this file.
1
9#ifndef __W_BUFFER_H__
10#define __W_BUFFER_H__
11
12#include <inttypes.h>
13#include <stddef.h>
14#include "ws_symbol_export.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20#define SOME_FUNCTIONS_ARE_INLINE
21
22typedef struct Buffer {
23 uint8_t *data;
24 size_t allocated;
25 size_t start;
26 size_t first_free;
27} Buffer;
28
29WS_DLL_PUBLIC
30void ws_buffer_init(Buffer* buffer, size_t space);
31WS_DLL_PUBLIC
32void ws_buffer_free(Buffer* buffer);
33WS_DLL_PUBLIC
34void ws_buffer_assure_space(Buffer* buffer, size_t space);
35WS_DLL_PUBLIC
36void ws_buffer_append(Buffer* buffer, const uint8_t *from, size_t bytes);
37WS_DLL_PUBLIC
38void ws_buffer_remove_start(Buffer* buffer, size_t bytes);
39WS_DLL_PUBLIC
40void ws_buffer_cleanup(void);
41
42#ifdef SOME_FUNCTIONS_ARE_INLINE
43/* Or inlines */
44static inline void
45ws_buffer_clean(Buffer *buffer)
46{
47 buffer->start = 0;
48 buffer->first_free = 0;
49}
50
51static inline void
52ws_buffer_increase_length(Buffer* buffer, size_t bytes)
53{
54 buffer->first_free += bytes;
55}
56
57static inline size_t
58ws_buffer_length(const Buffer* buffer)
59{
60 return buffer->first_free - buffer->start;
61}
62
63static inline uint8_t *
64ws_buffer_start_ptr(const Buffer* buffer)
65{
66 return buffer->data + buffer->start;
67}
68
69static inline uint8_t *
70ws_buffer_end_ptr(const Buffer* buffer)
71{
72 return buffer->data + buffer->first_free;
73}
74
75static inline void
76ws_buffer_append_buffer(Buffer* buffer, Buffer* src_buffer)
77{
78 ws_buffer_append(buffer, ws_buffer_start_ptr(src_buffer), ws_buffer_length(src_buffer));
79}
80#else
81 WS_DLL_PUBLIC
82 void ws_buffer_clean(Buffer* buffer);
83 WS_DLL_PUBLIC
84 void ws_buffer_increase_length(Buffer* buffer, size_t bytes);
85 WS_DLL_PUBLIC
86 size_t ws_buffer_length(const Buffer* buffer);
87 WS_DLL_PUBLIC
88 uint8_t* ws_buffer_start_ptr(const Buffer* buffer);
89 WS_DLL_PUBLIC
90 uint8_t* ws_buffer_end_ptr(const Buffer* buffer);
91 WS_DLL_PUBLIC
92 void ws_buffer_append_buffer(Buffer* buffer, Buffer* src_buffer);
93#endif
94
95#ifdef __cplusplus
96}
97#endif /* __cplusplus */
98
99#endif
WS_DLL_PUBLIC void ws_buffer_remove_start(Buffer *buffer, size_t bytes)
Definition buffer.c:113
Definition buffer.h:22
Definition mcast_stream.h:30