libcbor  0.5.0
libcbor is a C library for parsing and generating CBOR, the general-purpose schema-less binary data format.
data.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2017 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_DATA_H
9 #define LIBCBOR_DATA_H
10 
11 #include <stdlib.h>
12 #include <stddef.h>
13 #include <stdint.h>
14 #include <stdbool.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 typedef const unsigned char * cbor_data;
21 typedef unsigned char * cbor_mutable_data;
22 
24 typedef enum cbor_type {
33 } cbor_type;
34 
36 typedef enum {
44 
46 typedef enum {
52 
54 typedef enum {
60 
62 typedef enum {
66 
68 typedef enum {
74 } _cbor_ctrl;
75 
78  cbor_int_width width;
79 };
80 
83  size_t length;
84  _cbor_dst_metadata type;
85 };
86 
89  size_t length;
90  size_t codepoint_count; /* Sum of chunks' codepoint_counts for indefinite strings */
91  _cbor_dst_metadata type;
92 };
93 
96  size_t allocated;
97  size_t end_ptr;
98  _cbor_dst_metadata type;
99 };
100 
103  size_t allocated;
104  size_t end_ptr;
105  _cbor_dst_metadata type;
106 };
107 
116  uint64_t value;
117 };
118 
121  cbor_float_width width;
122  uint8_t ctrl;
123 };
124 
127  float as_float;
128  uint32_t as_uint;
129 };
130 
133  double as_double;
134  uint64_t as_uint;
135 };
136 
139  struct _cbor_int_metadata int_metadata;
140  struct _cbor_bytestring_metadata bytestring_metadata;
141  struct _cbor_string_metadata string_metadata;
142  struct _cbor_array_metadata array_metadata;
143  struct _cbor_map_metadata map_metadata;
144  struct _cbor_tag_metadata tag_metadata;
145  struct _cbor_float_ctrl_metadata float_ctrl_metadata;
146 };
147 
149 typedef struct cbor_item_t {
151  union cbor_item_metadata metadata;
153  size_t refcount;
155  cbor_type type;
157  unsigned char * data;
158 } cbor_item_t;
159 
165  size_t chunk_count;
168 };
169 
171 struct cbor_error {
173  size_t position;
175  cbor_error_code code;
176 };
177 
179 struct cbor_pair {
180  cbor_item_t * key, * value;
181 };
182 
186  struct cbor_error error;
188  size_t read;
189 };
190 
191 
198 };
199 
203  size_t read;
205  enum cbor_decoder_status status;
206 };
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif //LIBCBOR_DATA_H
Malformed or reserved MTB/value.
Definition: data.h:197
struct cbor_item_t cbor_item_t
The item handle.
High-level decoding result.
Definition: data.h:184
size_t end_ptr
Definition: data.h:97
cbor_item_t ** chunks
Definition: data.h:167
6 - tags
Definition: data.h:31
cbor_float_width
Possible widths of CBOR_TYPE_FLOAT_CTRL items.
Definition: data.h:54
float as_float
Definition: data.h:127
3 - strings
Definition: data.h:28
OK, finished.
Definition: data.h:194
size_t read
Bytes read.
Definition: data.h:203
2 - byte strings
Definition: data.h:27
Internal use - ctrl and special values.
Definition: data.h:55
_cbor_ctrl
Semantic mapping for CTRL simple values.
Definition: data.h:68
Integers specific metadata.
Definition: data.h:77
cbor_item_t * value
Definition: data.h:180
size_t position
Aproximate position.
Definition: data.h:173
size_t allocated
Definition: data.h:96
cbor_decoder_status
Streaming decoder result - status.
Definition: data.h:193
uint32_t as_uint
Definition: data.h:128
_cbor_dst_metadata type
Definition: data.h:84
Floats specific metadata - includes CTRL values.
Definition: data.h:120
Union of metadata across all possible types - discriminated in cbor_item_t.
Definition: data.h:138
_cbor_dst_metadata type
Definition: data.h:98
4 - arrays
Definition: data.h:29
size_t end_ptr
Definition: data.h:104
cbor_type type
Major type discriminator.
Definition: data.h:155
7 - decimals and special values (true, false, nil, ...)
Definition: data.h:32
Simple pair of items for use in maps.
Definition: data.h:179
size_t refcount
Reference count - initialize to 0.
Definition: data.h:153
cbor_error_code code
Description.
Definition: data.h:175
Maps specific metadata.
Definition: data.h:102
Double.
Definition: data.h:58
High-level decoding error.
Definition: data.h:171
Half float.
Definition: data.h:56
unsigned char * cbor_mutable_data
Definition: data.h:21
cbor_int_width
Possible widths of CBOR_TYPE_UINT items.
Definition: data.h:46
0 - positive integers
Definition: data.h:25
Arrays specific metadata.
Definition: data.h:95
size_t codepoint_count
Definition: data.h:90
cbor_error_code
Possible decoding errors.
Definition: data.h:36
Bytestrings specific metadata.
Definition: data.h:82
uint64_t as_uint
Definition: data.h:134
Streaming decoder result.
Definition: data.h:201
Defines cbor_item_t::data structure for indefinite strings and bytestrings.
Definition: data.h:164
const unsigned char * cbor_data
Definition: data.h:20
_cbor_dst_metadata type
Definition: data.h:105
struct cbor_item_t * tagged_item
Definition: data.h:115
Strings specific metadata.
Definition: data.h:88
cbor_float_width width
Definition: data.h:121
uint64_t value
Definition: data.h:116
cbor_type
Specifies the Major type of cbor_item_t.
Definition: data.h:24
_cbor_dst_metadata
Metadata for dynamically sized types.
Definition: data.h:62
Stack parsing algorithm failed.
Definition: data.h:42
Not enough data - mismatch with MTB.
Definition: data.h:195
unsigned char * data
Raw data block - interpretation depends on metadata.
Definition: data.h:157
size_t allocated
Definition: data.h:103
_cbor_dst_metadata type
Definition: data.h:91
cbor_int_width width
Definition: data.h:78
The item handle.
Definition: data.h:149
double as_double
Definition: data.h:133
1 - negative integers
Definition: data.h:26
Raw memory casts helper.
Definition: data.h:126
Memory error - item allocation failed.
Definition: data.h:41
size_t read
Number of bytes read.
Definition: data.h:188
Raw memory casts helper.
Definition: data.h:132
Buffer manipulation problem.
Definition: data.h:196
5 - maps
Definition: data.h:30
Single float.
Definition: data.h:57
Arrays specific metadata.
Definition: data.h:114