libcoap 4.3.5-develop-7be2515
Loading...
Searching...
No Matches
coap_str.h
Go to the documentation of this file.
1/*
2 * str.h -- strings to be used in the CoAP library
3 *
4 * Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
5 *
6 * SPDX-License-Identifier: BSD-2-Clause
7 *
8 * This file is part of the CoAP library libcoap. Please see README for terms
9 * of use.
10 */
11
17#ifndef COAP_STR_H_
18#define COAP_STR_H_
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
31/*
32 * Note: string and binary use equivalent objects.
33 * string is likely to contain readable textual information, binary will not.
34 */
35
39typedef struct coap_string_t {
40 size_t length;
41 uint8_t *s;
43
47typedef struct coap_str_const_t {
48 size_t length;
49 const uint8_t *s;
51
52#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
53
57typedef struct coap_binary_t {
58 size_t length;
59 uint8_t *s;
61
65typedef struct coap_bin_const_t {
66 size_t length;
67 const uint8_t *s;
69
79
83typedef union {
84 const char *s_byte;
85 const uint8_t *u_byte;
87
98coap_string_t *coap_new_string(size_t size);
99
106
117coap_str_const_t *coap_new_str_const(const uint8_t *data, size_t size);
118
125
136coap_binary_t *coap_new_binary(size_t size);
137
144
158coap_binary_t *coap_resize_binary(coap_binary_t *binary, size_t new_size);
159
171coap_bin_const_t *coap_new_bin_const(const uint8_t *data, size_t size);
172
179
180#ifndef COAP_MAX_STR_CONST_FUNC
181#define COAP_MAX_STR_CONST_FUNC 2
182#endif /* COAP_MAX_STR_CONST_FUNC */
183
197coap_str_const_t *coap_make_str_const(const char *string);
198
208#define coap_string_equal(string1,string2) \
209 ((string1)->length == (string2)->length && ((string1)->length == 0 || \
210 ((string1)->s && (string2)->s && \
211 memcmp((string1)->s, (string2)->s, (string1)->length) == 0)))
212
222#define coap_binary_equal(binary1,binary2) \
223 ((binary1)->length == (binary2)->length && ((binary1)->length == 0 || \
224 ((binary1)->s && (binary2)->s && \
225 memcmp((binary1)->s, (binary2)->s, (binary1)->length) == 0)))
226
229#ifdef __cplusplus
230}
231#endif
232
233#endif /* COAP_STR_H_ */
void coap_delete_bin_const(coap_bin_const_t *binary)
Deletes the given const binary data and releases any memory allocated.
Definition coap_str.c:129
void coap_delete_str_const(coap_str_const_t *string)
Deletes the given const string and releases any memory allocated.
Definition coap_str.c:65
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
Definition coap_str.c:81
coap_str_const_t * coap_make_str_const(const char *string)
Take the specified byte array (text) and create a coap_str_const_t *.
Definition coap_str.c:70
coap_bin_const_t * coap_new_bin_const(const uint8_t *data, size_t size)
Take the specified byte array (text) and create a coap_bin_const_t * Returns a new const binary objec...
Definition coap_str.c:119
coap_binary_t * coap_resize_binary(coap_binary_t *binary, size_t new_size)
Resizes the given coap_binary_t object.
Definition coap_str.c:86
void coap_delete_binary(coap_binary_t *binary)
Deletes the given coap_binary_t object and releases any memory allocated.
Definition coap_str.c:114
coap_string_t * coap_new_string(size_t size)
Returns a new string object with at least size+1 bytes storage allocated.
Definition coap_str.c:21
coap_str_const_t * coap_new_str_const(const uint8_t *data, size_t size)
Returns a new const string object with at least size+1 bytes storage allocated, and the provided data...
Definition coap_str.c:55
void coap_delete_string(coap_string_t *string)
Deletes the given string and releases any memory allocated.
Definition coap_str.c:50
CoAP binary data definition with const data.
Definition coap_str.h:65
size_t length
length of binary data
Definition coap_str.h:66
const uint8_t * s
read-only binary data
Definition coap_str.h:67
CoAP binary data definition.
Definition coap_str.h:57
size_t length
length of binary data
Definition coap_str.h:58
uint8_t * s
binary data
Definition coap_str.h:59
CoAP string data definition with const data.
Definition coap_str.h:47
const uint8_t * s
read-only string data
Definition coap_str.h:49
size_t length
length of string
Definition coap_str.h:48
CoAP string data definition.
Definition coap_str.h:39
uint8_t * s
string data
Definition coap_str.h:41
size_t length
length of string
Definition coap_str.h:40
CoAP union for handling signed / unsigned chars.
Definition coap_str.h:83
const char * s_byte
signed char ptr
Definition coap_str.h:84
const uint8_t * u_byte
unsigned char ptr
Definition coap_str.h:85
CoAP union for binary, string etc.
Definition coap_str.h:73
coap_str_const_t sc
Definition coap_str.h:75
coap_string_t st
Definition coap_str.h:74
coap_binary_t bt
Definition coap_str.h:76
coap_bin_const_t bc
Definition coap_str.h:77