proton  0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
codec.h
Go to the documentation of this file.
1 #ifndef PROTON_CODEC_H
2 #define PROTON_CODEC_H 1
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include <proton/import_export.h>
26 #include <proton/object.h>
27 #include <proton/types.h>
28 #ifndef __cplusplus
29 #include <stdbool.h>
30 #include <stdint.h>
31 #else
32 #include <proton/type_compat.h>
33 #endif
34 #include <stdarg.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 typedef enum {
41  PN_NULL = 1,
42  PN_BOOL = 2,
43  PN_UBYTE = 3,
44  PN_BYTE = 4,
45  PN_USHORT = 5,
46  PN_SHORT = 6,
47  PN_UINT = 7,
48  PN_INT = 8,
49  PN_CHAR = 9,
50  PN_ULONG = 10,
51  PN_LONG = 11,
53  PN_FLOAT = 13,
54  PN_DOUBLE = 14,
58  PN_UUID = 18,
59  PN_BINARY = 19,
60  PN_STRING = 20,
61  PN_SYMBOL = 21,
63  PN_ARRAY = 23,
64  PN_LIST = 24,
65  PN_MAP = 25
66 } pn_type_t;
67 
68 PN_EXTERN const char *pn_type_name(pn_type_t type);
69 
70 typedef struct {
72  union {
73  bool as_bool;
74  uint8_t as_ubyte;
75  int8_t as_byte;
76  uint16_t as_ushort;
77  int16_t as_short;
78  uint32_t as_uint;
79  int32_t as_int;
81  uint64_t as_ulong;
82  int64_t as_long;
84  float as_float;
85  double as_double;
91  size_t as_count;
92  } u;
93 } pn_atom_t;
94 
95 // data
96 
97 typedef struct pn_data_t pn_data_t;
98 
99 PN_EXTERN pn_data_t *pn_data(size_t capacity);
100 PN_EXTERN void pn_data_free(pn_data_t *data);
102 PN_EXTERN const char *pn_data_error(pn_data_t *data);
103 PN_EXTERN int pn_data_vfill(pn_data_t *data, const char *fmt, va_list ap);
104 PN_EXTERN int pn_data_fill(pn_data_t *data, const char *fmt, ...);
105 PN_EXTERN int pn_data_vscan(pn_data_t *data, const char *fmt, va_list ap);
106 PN_EXTERN int pn_data_scan(pn_data_t *data, const char *fmt, ...);
107 
108 PN_EXTERN void pn_data_clear(pn_data_t *data);
109 PN_EXTERN size_t pn_data_size(pn_data_t *data);
111 PN_EXTERN bool pn_data_next(pn_data_t *data);
112 PN_EXTERN bool pn_data_prev(pn_data_t *data);
113 PN_EXTERN bool pn_data_enter(pn_data_t *data);
114 PN_EXTERN bool pn_data_exit(pn_data_t *data);
115 PN_EXTERN bool pn_data_lookup(pn_data_t *data, const char *name);
116 
118 
120 PN_EXTERN int pn_data_format(pn_data_t *data, char *bytes, size_t *size);
121 PN_EXTERN ssize_t pn_data_encode(pn_data_t *data, char *bytes, size_t size);
122 PN_EXTERN ssize_t pn_data_decode(pn_data_t *data, const char *bytes, size_t size);
123 
126 PN_EXTERN int pn_data_put_array(pn_data_t *data, bool described, pn_type_t type);
129 PN_EXTERN int pn_data_put_bool(pn_data_t *data, bool b);
130 PN_EXTERN int pn_data_put_ubyte(pn_data_t *data, uint8_t ub);
131 PN_EXTERN int pn_data_put_byte(pn_data_t *data, int8_t b);
132 PN_EXTERN int pn_data_put_ushort(pn_data_t *data, uint16_t us);
133 PN_EXTERN int pn_data_put_short(pn_data_t *data, int16_t s);
134 PN_EXTERN int pn_data_put_uint(pn_data_t *data, uint32_t ui);
135 PN_EXTERN int pn_data_put_int(pn_data_t *data, int32_t i);
137 PN_EXTERN int pn_data_put_ulong(pn_data_t *data, uint64_t ul);
138 PN_EXTERN int pn_data_put_long(pn_data_t *data, int64_t l);
140 PN_EXTERN int pn_data_put_float(pn_data_t *data, float f);
141 PN_EXTERN int pn_data_put_double(pn_data_t *data, double d);
150 
151 PN_EXTERN size_t pn_data_get_list(pn_data_t *data);
152 PN_EXTERN size_t pn_data_get_map(pn_data_t *data);
159 PN_EXTERN uint8_t pn_data_get_ubyte(pn_data_t *data);
160 PN_EXTERN int8_t pn_data_get_byte(pn_data_t *data);
161 PN_EXTERN uint16_t pn_data_get_ushort(pn_data_t *data);
162 PN_EXTERN int16_t pn_data_get_short(pn_data_t *data);
163 PN_EXTERN uint32_t pn_data_get_uint(pn_data_t *data);
164 PN_EXTERN int32_t pn_data_get_int(pn_data_t *data);
166 PN_EXTERN uint64_t pn_data_get_ulong(pn_data_t *data);
167 PN_EXTERN int64_t pn_data_get_long(pn_data_t *data);
180 
181 PN_EXTERN int pn_data_copy(pn_data_t *data, pn_data_t *src);
183 PN_EXTERN int pn_data_appendn(pn_data_t *data, pn_data_t *src, int limit);
185 PN_EXTERN void pn_data_widen(pn_data_t *data);
188 
189 
190 PN_EXTERN void pn_data_dump(pn_data_t *data);
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif /* codec.h */