libcoap
4.3.5
Toggle main menu visibility
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
16
17
#ifndef COAP_STR_H_
18
#define COAP_STR_H_
19
20
#include <string.h>
21
22
29
30
/*
31
* Note: string and binary use equivalent objects.
32
* string is likely to contain readable textual information, binary will not.
33
*/
34
38
typedef
struct
coap_string_t
{
39
size_t
length
;
40
uint8_t *
s
;
41
}
coap_string_t
;
42
46
typedef
struct
coap_str_const_t
{
47
size_t
length
;
48
const
uint8_t *
s
;
49
}
coap_str_const_t
;
50
51
#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
52
56
typedef
struct
coap_binary_t
{
57
size_t
length
;
58
uint8_t *
s
;
59
}
coap_binary_t
;
60
64
typedef
struct
coap_bin_const_t
{
65
size_t
length
;
66
const
uint8_t *
s
;
67
}
coap_bin_const_t
;
68
72
typedef
union
{
73
const
char
*
s_byte
;
74
const
uint8_t *
u_byte
;
75
}
coap_const_char_ptr_t
;
76
87
coap_string_t
*
coap_new_string
(
size_t
size);
88
94
void
coap_delete_string
(
coap_string_t
*
string
);
95
106
coap_str_const_t
*
coap_new_str_const
(
const
uint8_t *data,
size_t
size);
107
113
void
coap_delete_str_const
(
coap_str_const_t
*
string
);
114
125
coap_binary_t
*
coap_new_binary
(
size_t
size);
126
132
void
coap_delete_binary
(
coap_binary_t
*binary);
133
147
coap_binary_t
*
coap_resize_binary
(
coap_binary_t
*binary,
size_t
new_size);
148
160
coap_bin_const_t
*
coap_new_bin_const
(
const
uint8_t *data,
size_t
size);
161
167
void
coap_delete_bin_const
(
coap_bin_const_t
*binary);
168
169
#ifndef COAP_MAX_STR_CONST_FUNC
170
#define COAP_MAX_STR_CONST_FUNC 2
171
#endif
/* COAP_MAX_STR_CONST_FUNC */
172
186
coap_str_const_t
*
coap_make_str_const
(
const
char
*
string
);
187
197
#define coap_string_equal(string1,string2) \
198
((string1)->length == (string2)->length && ((string1)->length == 0 || \
199
((string1)->s && (string2)->s && \
200
memcmp((string1)->s, (string2)->s, (string1)->length) == 0)))
201
211
#define coap_binary_equal(binary1,binary2) \
212
((binary1)->length == (binary2)->length && ((binary1)->length == 0 || \
213
((binary1)->s && (binary2)->s && \
214
memcmp((binary1)->s, (binary2)->s, (binary1)->length) == 0)))
215
217
218
#endif
/* COAP_STR_H_ */
coap_delete_bin_const
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:120
coap_delete_str_const
void coap_delete_str_const(coap_str_const_t *string)
Deletes the given const string and releases any memory allocated.
Definition
coap_str.c:61
coap_new_binary
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:77
coap_make_str_const
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:66
coap_new_bin_const
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:110
coap_resize_binary
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:82
coap_delete_binary
void coap_delete_binary(coap_binary_t *binary)
Deletes the given coap_binary_t object and releases any memory allocated.
Definition
coap_str.c:105
coap_new_string
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_new_str_const
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:51
coap_delete_string
void coap_delete_string(coap_string_t *string)
Deletes the given string and releases any memory allocated.
Definition
coap_str.c:46
coap_bin_const_t
CoAP binary data definition with const data.
Definition
coap_str.h:64
coap_bin_const_t::length
size_t length
length of binary data
Definition
coap_str.h:65
coap_bin_const_t::s
const uint8_t * s
read-only binary data
Definition
coap_str.h:66
coap_binary_t
CoAP binary data definition.
Definition
coap_str.h:56
coap_binary_t::length
size_t length
length of binary data
Definition
coap_str.h:57
coap_binary_t::s
uint8_t * s
binary data
Definition
coap_str.h:58
coap_str_const_t
CoAP string data definition with const data.
Definition
coap_str.h:46
coap_str_const_t::s
const uint8_t * s
read-only string data
Definition
coap_str.h:48
coap_str_const_t::length
size_t length
length of string
Definition
coap_str.h:47
coap_string_t
CoAP string data definition.
Definition
coap_str.h:38
coap_string_t::s
uint8_t * s
string data
Definition
coap_str.h:40
coap_string_t::length
size_t length
length of string
Definition
coap_str.h:39
coap_const_char_ptr_t
CoAP union for handling signed / unsigned chars.
Definition
coap_str.h:72
coap_const_char_ptr_t::s_byte
const char * s_byte
signed char ptr
Definition
coap_str.h:73
coap_const_char_ptr_t::u_byte
const uint8_t * u_byte
unsigned char ptr
Definition
coap_str.h:74
include
coap3
coap_str.h
Generated on
for libcoap by
1.17.0