1 /*
2  * q_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.md
9  */
10 
11 
12 #ifndef __Q_USEFUL_BUF_H__
13 #define __Q_USEFUL_BUF_H__
14 
15 #include "UsefulBuf.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 
22 /**
23  * \file q_useful_buf.h
24  *
25  * \brief This is a TF-M coding style version of UsefulBuf.
26  *        See UsefulBuf for documentation of these functions.
27  */
28 
29 
30 #define NULL_Q_USEFUL_BUF_C  NULLUsefulBufC
31 
32 #define NULL_Q_USEFUL_BUF    NULLUsefulBuf
33 
34 
q_useful_buf_c_is_null(struct q_useful_buf_c in)35 static inline int q_useful_buf_c_is_null(struct q_useful_buf_c in)
36 {
37     return UsefulBuf_IsNULLC(in);
38 }
39 
40 
q_useful_buf_is_null(struct q_useful_buf in)41 static inline int q_useful_buf_is_null(struct q_useful_buf in)
42 {
43     return UsefulBuf_IsNULL(in);
44 }
45 
46 
q_useful_buf_c_is_empty(struct q_useful_buf_c in)47 static inline int q_useful_buf_c_is_empty(struct q_useful_buf_c in)
48 {
49     return UsefulBuf_IsEmptyC(in);
50 }
51 
q_useful_buf_is_empty(struct q_useful_buf in)52 static inline int q_useful_buf_is_empty(struct q_useful_buf in)
53 {
54     return UsefulBuf_IsEmpty(in);
55 }
56 
57 
q_useful_buf_is_null_or_empty(struct q_useful_buf in)58 static inline int q_useful_buf_is_null_or_empty(struct q_useful_buf in)
59 {
60     return UsefulBuf_IsNULLOrEmpty(in);
61 }
62 
63 
q_useful_buf_c_is_null_or_empty(struct q_useful_buf_c in)64 static inline int q_useful_buf_c_is_null_or_empty(struct q_useful_buf_c in)
65 {
66     return UsefulBuf_IsNULLOrEmptyC(in);
67 }
68 
69 
q_useful_buf_unconst(struct q_useful_buf_c in)70 static inline struct q_useful_buf q_useful_buf_unconst(struct q_useful_buf_c in)
71 {
72     return UsefulBuf_Unconst(in);
73 }
74 
75 #define Q_USEFUL_BUF_FROM_SZ_LITERAL UsefulBuf_FROM_SZ_LITERAL
76 
77 #define Q_USEFUL_BUF_FROM_BYTE_ARRAY_LITERAL  UsefulBuf_FROM_BYTE_ARRAY_LITERAL
78 
79 #define Q_USEFUL_BUF_MAKE_STACK_UB UsefulBuf_MAKE_STACK_UB
80 
81 #define Q_USEFUL_BUF_FROM_BYTE_ARRAY UsefulBuf_FROM_BYTE_ARRAY
82 
83 
q_useful_buf_from_sz(const char * string)84 static inline struct q_useful_buf_c q_useful_buf_from_sz(const char *string)
85 {
86     return UsefulBuf_FromSZ(string);
87 }
88 
89 static inline struct q_useful_buf_c
useful_buf_copy_offset(struct q_useful_buf dest,size_t offset,struct q_useful_buf_c src)90 useful_buf_copy_offset(struct q_useful_buf dest,
91                        size_t offset,
92                        struct q_useful_buf_c src)
93 {
94     return UsefulBuf_CopyOffset(dest, offset, src);
95 }
96 
97 
98 
q_useful_buf_copy(struct q_useful_buf dest,struct q_useful_buf_c src)99 static inline struct q_useful_buf_c q_useful_buf_copy(struct q_useful_buf dest,
100                                                      struct q_useful_buf_c src)
101 {
102     return UsefulBuf_Copy(dest, src);
103 }
104 
105 
q_useful_buf_set(struct q_useful_buf dest,uint8_t value)106 static inline struct q_useful_buf_c q_useful_buf_set(struct q_useful_buf dest,
107                                                      uint8_t value)
108 {
109     return UsefulBuf_Set(dest, value);
110 }
111 
112 
q_useful_buf_copy_ptr(struct q_useful_buf dest,const void * ptr,size_t len)113 static inline struct q_useful_buf_c q_useful_buf_copy_ptr(struct q_useful_buf dest,
114                                                           const void *ptr,
115                                                           size_t len)
116 {
117     return UsefulBuf_CopyPtr(dest, ptr, len);
118 }
119 
120 
q_useful_buf_head(struct q_useful_buf_c buf,size_t amount)121 static inline struct q_useful_buf_c q_useful_buf_head(struct q_useful_buf_c buf,
122                                                       size_t amount)
123 {
124     return UsefulBuf_Head(buf, amount);
125 }
126 
q_useful_buf_tail(struct q_useful_buf_c buf,size_t amount)127 static inline struct q_useful_buf_c q_useful_buf_tail(struct q_useful_buf_c buf,
128                                                       size_t amount)
129 {
130     return UsefulBuf_Tail(buf, amount);
131 }
132 
q_useful_buf_compare(const struct q_useful_buf_c buf1,const struct q_useful_buf_c buf2)133 static inline int q_useful_buf_compare(const struct q_useful_buf_c buf1,
134                                        const struct q_useful_buf_c buf2)
135 {
136     return UsefulBuf_Compare(buf1, buf2);
137 }
138 
q_useful_buf_is_value(const struct q_useful_buf_c buf,uint8_t uValue)139 static inline size_t q_useful_buf_is_value(const struct q_useful_buf_c buf,
140                                            uint8_t uValue)
141 {
142     return UsefulBuf_IsValue(buf, uValue);
143 }
144 
145 static inline size_t
q_useful_buf_find_bytes(const struct q_useful_buf_c bytes_to_search,const struct q_useful_buf_c bytes_to_find)146 q_useful_buf_find_bytes(const struct q_useful_buf_c bytes_to_search,
147                         const struct q_useful_buf_c bytes_to_find)
148 {
149     return UsefulBuf_FindBytes(bytes_to_search, bytes_to_find);
150 }
151 
152 
153 #ifdef __cplusplus
154 }
155 #endif
156 
157 #endif /* __Q_USEFUL_BUF_H__ */
158