Commit | Line | Data |
---|---|---|
01dc0eed | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
01dc0eed | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
01dc0eed | 5 | * |
01dc0eed JG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_BUFFER_VIEW_H | |
9 | #define LTTNG_BUFFER_VIEW_H | |
10 | ||
11 | #include <stddef.h> | |
12 | #include <stdint.h> | |
ff28f865 | 13 | #include <common/macros.h> |
01dc0eed JG |
14 | |
15 | struct lttng_dynamic_buffer; | |
16 | ||
17 | struct lttng_buffer_view { | |
18 | const char *data; | |
19 | size_t size; | |
20 | }; | |
21 | ||
b35aac84 JG |
22 | /** |
23 | * Return a buffer view referencing a subset of the memory referenced by a raw | |
24 | * pointer. | |
25 | * | |
26 | * @src Source buffer to reference | |
27 | * @offset Offset to apply to the source memory buffer | |
28 | * @len Length of the memory contents to reference. | |
29 | * | |
30 | * Note that a buffer view never assumes the ownership of the memory it | |
31 | * references. | |
32 | */ | |
33 | LTTNG_HIDDEN | |
34 | struct lttng_buffer_view lttng_buffer_view_init( | |
35 | const char *src, size_t offset, ptrdiff_t len); | |
36 | ||
01dc0eed JG |
37 | /** |
38 | * Return a buffer view referencing a subset of the memory referenced by another | |
39 | * view. | |
40 | * | |
41 | * @src Source view to reference | |
42 | * @offset Offset to apply to the source memory content | |
43 | * @len Length of the memory contents to reference. Passing -1 will | |
44 | * cause the view to reference the whole view from the offset | |
45 | * provided. | |
46 | * | |
47 | * Note that a buffer view never assumes the ownership of the memory it | |
48 | * references. | |
49 | */ | |
ff28f865 | 50 | LTTNG_HIDDEN |
01dc0eed JG |
51 | struct lttng_buffer_view lttng_buffer_view_from_view( |
52 | const struct lttng_buffer_view *src, size_t offset, | |
53 | ptrdiff_t len); | |
54 | ||
55 | /** | |
56 | * Return a buffer view referencing a subset of the memory referenced by a | |
57 | * dynamic buffer. | |
58 | * | |
59 | * @src Source dynamic buffer to reference | |
60 | * @offset Offset to apply to the source memory content | |
61 | * @len Length of the memory contents to reference. Passing -1 will | |
62 | * cause the view to reference the whole dynamic buffer from the | |
63 | * offset provided. | |
64 | * | |
65 | * Note that a buffer view never assumes the ownership of the memory it | |
66 | * references. | |
67 | */ | |
ff28f865 | 68 | LTTNG_HIDDEN |
01dc0eed JG |
69 | struct lttng_buffer_view lttng_buffer_view_from_dynamic_buffer( |
70 | const struct lttng_dynamic_buffer *src, size_t offset, | |
71 | ptrdiff_t len); | |
72 | ||
73 | #endif /* LTTNG_BUFFER_VIEW_H */ |