moddef-c
Loading...
Searching...
No Matches
str.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: Apache-2.0
2
3
/* Length-delimited strings. Protobuf strings are not NUL-terminated, and
4
* document views point straight into the serialized buffer, so every
5
* identifier in the API is an (pointer, length) pair. */
6
#ifndef MODDEF_STR_H
7
#define MODDEF_STR_H
8
9
#include <stdbool.h>
10
#include <stdint.h>
11
#include <string.h>
12
13
typedef
struct
md_str
{
14
const
char
*
p
;
15
uint16_t
len
;
16
}
md_str_t
;
17
18
/* String literal → md_str_t (compile-time length). */
19
#define MD_STR(lit) ((md_str_t){(lit), (uint16_t)(sizeof(lit) - 1)})
20
21
static
inline
md_str_t
md_str_cstr(
const
char
*s)
22
{
23
md_str_t
out = {s, (uint16_t)(s ? strlen(s) : 0)};
24
return
out;
25
}
26
27
static
inline
bool
md_str_eq(
md_str_t
a,
md_str_t
b)
28
{
29
return
a.
len
== b.
len
&& (a.
len
== 0 || memcmp(a.
p
, b.
p
, a.
len
) == 0);
30
}
31
32
/* Raw byte range inside a serialized document. */
33
typedef
struct
md_bytes
{
34
const
uint8_t *
p
;
35
uint32_t
len
;
36
}
md_bytes_t
;
37
38
#endif
/* MODDEF_STR_H */
md_str_t
struct md_str md_str_t
md_bytes_t
struct md_bytes md_bytes_t
md_bytes
Definition
str.h:33
md_bytes::len
uint32_t len
Definition
str.h:35
md_bytes::p
const uint8_t * p
Definition
str.h:34
md_str
Definition
str.h:13
md_str::len
uint16_t len
Definition
str.h:15
md_str::p
const char * p
Definition
str.h:14
include
moddef
str.h
Generated by
1.9.8