Mbed OS Reference
Loading...
Searching...
No Matches
useful_buf.h
Go to the documentation of this file.
1/*
2 * useful_buf.h
3 *
4 * Copyright 2019, Laurence Lundblade
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 *
8 * See BSD-3-Clause license in README.mdE.
9 */
10
11
12#ifndef __USEFUL_BUF_H__
13#define __USEFUL_BUF_H__
14
15#include "UsefulBuf.h"
16
17
18/**
19 * \file useful_buf.h
20 *
21 * \brief This is a TF-M coding style version of UsefulBuf.
22 * See UsefulBuf for documentation of these functions.
23 */
24
25
26#define NULL_USEFUL_BUF_C NULLUsefulBufC
27
28#define NULL_USEFUL_BUF NULLUsefulBuf
29
30
31static inline int useful_buf_c_is_null(struct useful_buf_c in)
32{
33 return UsefulBuf_IsNULLC(in);
34}
35
36
37static inline int useful_buf_is_null(struct useful_buf in)
38{
39 return UsefulBuf_IsNULL(in);
40}
41
42
43static inline int useful_buf_c_is_empty(struct useful_buf_c in)
44{
45 return UsefulBuf_IsEmptyC(in);
46}
47
48static inline int useful_buf_is_empty(struct useful_buf in)
49{
50 return UsefulBuf_IsEmpty(in);
51}
52
53
54static inline int useful_buf_is_null_or_empty(struct useful_buf in)
55{
56 return UsefulBuf_IsNULLOrEmpty(in);
57}
58
59
60static inline int useful_buf_c_is_null_or_empty(struct useful_buf_c in)
61{
62 return UsefulBuf_IsNULLOrEmptyC(in);
63}
64
65
66static inline struct useful_buf useful_buf_unconst(struct useful_buf_c in)
67{
68 return UsefulBuf_Unconst(in);
69}
70
71#define USEFUL_BUF_FROM_SZ_LITERAL UsefulBuf_FROM_SZ_LITERAL
72
73#define USEFUL_BUF_FROM_BYTE_ARRAY_LITERAL UsefulBuf_FROM_BYTE_ARRAY_LITERAL
74
75#define USEFUL_BUF_MAKE_STACK_UB UsefulBuf_MAKE_STACK_UB
76
77#define USEFUL_BUF_FROM_BYTE_ARRAY UsefulBuf_FROM_BYTE_ARRAY
78
79
80static inline struct useful_buf_c useful_buf_from_sz(const char *string)
81{
82 return UsefulBuf_FromSZ(string);
83}
84
85static inline struct
86useful_buf_c useful_buf_copy_offset(struct useful_buf dest,
87 size_t offset,
88 struct useful_buf_c src)
89{
90 return UsefulBuf_CopyOffset(dest, offset, src);
91}
92
93
94
95static inline struct useful_buf_c useful_buf_copy(struct useful_buf dest,
96 struct useful_buf_c src)
97{
98 return UsefulBuf_Copy(dest, src);
99}
100
101
102static inline struct useful_buf_c useful_buf_set(struct useful_buf dest,
103 uint8_t value)
104{
105 return UsefulBuf_Set(dest, value);
106}
107
108
109static inline struct useful_buf_c useful_buf_copy_ptr(struct useful_buf dest,
110 const void *ptr,
111 size_t len)
112{
113 return UsefulBuf_CopyPtr(dest, ptr, len);
114}
115
116
117static inline struct useful_buf_c useful_buf_head(struct useful_buf_c buf,
118 size_t amount)
119{
120 return UsefulBuf_Head(buf, amount);
121}
122
123static inline struct useful_buf_c useful_buf_tail(struct useful_buf_c buf,
124 size_t amount)
125{
126 return UsefulBuf_Tail(buf, amount);
127}
128
129static inline int useful_buf_compare(const struct useful_buf_c buf1,
130 const struct useful_buf_c buf2)
131{
132 return UsefulBuf_Compare(buf1, buf2);
133}
134
135static inline size_t
136useful_buf_find_bytes(const struct useful_buf_c bytes_to_search,
137 const struct useful_buf_c bytes_to_find)
138{
139 return UsefulBuf_FindBytes(bytes_to_search, bytes_to_find);
140}
141
142
143#endif /* __USEFUL_BUF_H__ */
The goal of this code is to make buffer and pointer manipulation easier and safer when working with b...
size_t UsefulBuf_FindBytes(UsefulBufC BytesToSearch, UsefulBufC BytesToFind)
Find one UsefulBuf in another.
UsefulBufC UsefulBuf_CopyOffset(UsefulBuf Dest, size_t uOffset, const UsefulBufC Src)
Copy one UsefulBuf into another at an offset.
int UsefulBuf_Compare(const UsefulBufC UB1, const UsefulBufC UB2)
Compare two UsefulBufCs.
UsefulBufC and UsefulBuf are simple data structures to hold a pointer and length for a binary data.
Definition: UsefulBuf.h:149
The non-const UsefulBuf typically used for some allocated memory that is to be filled in.
Definition: UsefulBuf.h:160