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