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