xref: /freebsd/contrib/libcbor/src/cbor/callbacks.h (revision 5d3e7166)
1 /*
2  * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
3  *
4  * libcbor is free software; you can redistribute it and/or modify
5  * it under the terms of the MIT license. See LICENSE for details.
6  */
7 
8 #ifndef LIBCBOR_CALLBACKS_H
9 #define LIBCBOR_CALLBACKS_H
10 
11 #include <stdint.h>
12 
13 #include "cbor/cbor_export.h"
14 #include "cbor/common.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /** Callback prototype */
21 typedef void (*cbor_int8_callback)(void *, uint8_t);
22 
23 /** Callback prototype */
24 typedef void (*cbor_int16_callback)(void *, uint16_t);
25 
26 /** Callback prototype */
27 typedef void (*cbor_int32_callback)(void *, uint32_t);
28 
29 /** Callback prototype */
30 typedef void (*cbor_int64_callback)(void *, uint64_t);
31 
32 /** Callback prototype */
33 typedef void (*cbor_simple_callback)(void *);
34 
35 /** Callback prototype */
36 typedef void (*cbor_string_callback)(void *, cbor_data, uint64_t);
37 
38 /** Callback prototype */
39 typedef void (*cbor_collection_callback)(void *, uint64_t);
40 
41 /** Callback prototype */
42 typedef void (*cbor_float_callback)(void *, float);
43 
44 /** Callback prototype */
45 typedef void (*cbor_double_callback)(void *, double);
46 
47 /** Callback prototype */
48 typedef void (*cbor_bool_callback)(void *, bool);
49 
50 /** Callback bundle -- passed to the decoder */
51 struct cbor_callbacks {
52   /** Unsigned int */
53   cbor_int8_callback uint8;
54   /** Unsigned int */
55   cbor_int16_callback uint16;
56   /** Unsigned int */
57   cbor_int32_callback uint32;
58   /** Unsigned int */
59   cbor_int64_callback uint64;
60 
61   /** Negative int */
62   cbor_int64_callback negint64;
63   /** Negative int */
64   cbor_int32_callback negint32;
65   /** Negative int */
66   cbor_int16_callback negint16;
67   /** Negative int */
68   cbor_int8_callback negint8;
69 
70   /** Definite byte string */
71   cbor_simple_callback byte_string_start;
72   /** Indefinite byte string start */
73   cbor_string_callback byte_string;
74 
75   /** Definite string */
76   cbor_string_callback string;
77   /** Indefinite string start */
78   cbor_simple_callback string_start;
79 
80   /** Definite array */
81   cbor_simple_callback indef_array_start;
82   /** Indefinite array */
83   cbor_collection_callback array_start;
84 
85   /** Definite map */
86   cbor_simple_callback indef_map_start;
87   /** Indefinite map */
88   cbor_collection_callback map_start;
89 
90   /** Tags */
91   cbor_int64_callback tag;
92 
93   /** Half float */
94   cbor_float_callback float2;
95   /** Single float */
96   cbor_float_callback float4;
97   /** Double float */
98   cbor_double_callback float8;
99   /** Undef */
100   cbor_simple_callback undefined;
101   /** Null */
102   cbor_simple_callback null;
103   /** Bool */
104   cbor_bool_callback boolean;
105 
106   /** Indefinite item break */
107   cbor_simple_callback indef_break;
108 };
109 
110 /** Dummy callback implementation - does nothing */
111 CBOR_EXPORT void cbor_null_uint8_callback(void *, uint8_t);
112 
113 /** Dummy callback implementation - does nothing */
114 CBOR_EXPORT void cbor_null_uint16_callback(void *, uint16_t);
115 
116 /** Dummy callback implementation - does nothing */
117 CBOR_EXPORT void cbor_null_uint32_callback(void *, uint32_t);
118 
119 /** Dummy callback implementation - does nothing */
120 CBOR_EXPORT void cbor_null_uint64_callback(void *, uint64_t);
121 
122 /** Dummy callback implementation - does nothing */
123 CBOR_EXPORT void cbor_null_negint8_callback(void *, uint8_t);
124 
125 /** Dummy callback implementation - does nothing */
126 CBOR_EXPORT void cbor_null_negint16_callback(void *, uint16_t);
127 
128 /** Dummy callback implementation - does nothing */
129 CBOR_EXPORT void cbor_null_negint32_callback(void *, uint32_t);
130 
131 /** Dummy callback implementation - does nothing */
132 CBOR_EXPORT void cbor_null_negint64_callback(void *, uint64_t);
133 
134 /** Dummy callback implementation - does nothing */
135 CBOR_EXPORT void cbor_null_string_callback(void *, cbor_data, uint64_t);
136 
137 /** Dummy callback implementation - does nothing */
138 CBOR_EXPORT void cbor_null_string_start_callback(void *);
139 
140 /** Dummy callback implementation - does nothing */
141 CBOR_EXPORT void cbor_null_byte_string_callback(void *, cbor_data, uint64_t);
142 
143 /** Dummy callback implementation - does nothing */
144 CBOR_EXPORT void cbor_null_byte_string_start_callback(void *);
145 
146 /** Dummy callback implementation - does nothing */
147 CBOR_EXPORT void cbor_null_array_start_callback(void *, uint64_t);
148 
149 /** Dummy callback implementation - does nothing */
150 CBOR_EXPORT void cbor_null_indef_array_start_callback(void *);
151 
152 /** Dummy callback implementation - does nothing */
153 CBOR_EXPORT void cbor_null_map_start_callback(void *, uint64_t);
154 
155 /** Dummy callback implementation - does nothing */
156 CBOR_EXPORT void cbor_null_indef_map_start_callback(void *);
157 
158 /** Dummy callback implementation - does nothing */
159 CBOR_EXPORT void cbor_null_tag_callback(void *, uint64_t);
160 
161 /** Dummy callback implementation - does nothing */
162 CBOR_EXPORT void cbor_null_float2_callback(void *, float);
163 
164 /** Dummy callback implementation - does nothing */
165 CBOR_EXPORT void cbor_null_float4_callback(void *, float);
166 
167 /** Dummy callback implementation - does nothing */
168 CBOR_EXPORT void cbor_null_float8_callback(void *, double);
169 
170 /** Dummy callback implementation - does nothing */
171 CBOR_EXPORT void cbor_null_null_callback(void *);
172 
173 /** Dummy callback implementation - does nothing */
174 CBOR_EXPORT void cbor_null_undefined_callback(void *);
175 
176 /** Dummy callback implementation - does nothing */
177 CBOR_EXPORT void cbor_null_boolean_callback(void *, bool);
178 
179 /** Dummy callback implementation - does nothing */
180 CBOR_EXPORT void cbor_null_indef_break_callback(void *);
181 
182 /** Dummy callback bundle - does nothing */
183 CBOR_EXPORT extern const struct cbor_callbacks cbor_empty_callbacks;
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif  // LIBCBOR_CALLBACKS_H
190