Qpid Proton C API  0.18.1
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 #include <proton/error.h>
29 #include <proton/type_compat.h>
30 #include <stdarg.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
47 typedef enum {
51  PN_NULL = 1,
52 
56  PN_BOOL = 2,
57 
61  PN_UBYTE = 3,
62 
66  PN_BYTE = 4,
67 
71  PN_USHORT = 5,
72 
76  PN_SHORT = 6,
77 
81  PN_UINT = 7,
82 
86  PN_INT = 8,
87 
91  PN_CHAR = 9,
92 
96  PN_ULONG = 10,
97 
101  PN_LONG = 11,
102 
108 
112  PN_FLOAT = 13,
113 
117  PN_DOUBLE = 14,
118 
123 
128 
133 
137  PN_UUID = 18,
138 
142  PN_BINARY = 19,
143 
148  PN_STRING = 20,
149 
154  PN_SYMBOL = 21,
155 
160 
164  PN_ARRAY = 23,
165 
169  PN_LIST = 24,
170 
175  PN_MAP = 25,
176 
182 } pn_type_t;
183 
191 PN_EXTERN const char *pn_type_name(pn_type_t type);
192 
200 typedef struct {
206  union {
210  bool as_bool;
211 
215  uint8_t as_ubyte;
216 
220  int8_t as_byte;
221 
225  uint16_t as_ushort;
226 
230  int16_t as_short;
231 
235  uint32_t as_uint;
236 
240  int32_t as_int;
241 
245  pn_char_t as_char;
246 
250  uint64_t as_ulong;
251 
255  int64_t as_long;
256 
260  pn_timestamp_t as_timestamp;
261 
265  float as_float;
266 
270  double as_double;
271 
275  pn_decimal32_t as_decimal32;
276 
280  pn_decimal64_t as_decimal64;
281 
285  pn_decimal128_t as_decimal128;
286 
290  pn_uuid_t as_uuid;
291 
299  pn_bytes_t as_bytes;
300  } u;
301 } pn_atom_t;
302 
364 typedef struct pn_data_t pn_data_t;
365 
374 PN_EXTERN pn_data_t *pn_data(size_t capacity);
375 
381 PN_EXTERN void pn_data_free(pn_data_t *data);
382 
389 PN_EXTERN int pn_data_errno(pn_data_t *data);
390 
402 PN_EXTERN pn_error_t *pn_data_error(pn_data_t *data);
403 
407 PN_EXTERN int pn_data_vfill(pn_data_t *data, const char *fmt, va_list ap);
408 PN_EXTERN int pn_data_fill(pn_data_t *data, const char *fmt, ...);
409 PN_EXTERN int pn_data_vscan(pn_data_t *data, const char *fmt, va_list ap);
410 PN_EXTERN int pn_data_scan(pn_data_t *data, const char *fmt, ...);
423 PN_EXTERN void pn_data_clear(pn_data_t *data);
424 
434 PN_EXTERN size_t pn_data_size(pn_data_t *data);
435 
441 PN_EXTERN void pn_data_rewind(pn_data_t *data);
442 
451 PN_EXTERN bool pn_data_next(pn_data_t *data);
452 
461 PN_EXTERN bool pn_data_prev(pn_data_t *data);
462 
473 PN_EXTERN bool pn_data_enter(pn_data_t *data);
474 
484 PN_EXTERN bool pn_data_exit(pn_data_t *data);
485 
489 PN_EXTERN bool pn_data_lookup(pn_data_t *data, const char *name);
501 PN_EXTERN pn_type_t pn_data_type(pn_data_t *data);
502 
510 PN_EXTERN int pn_data_print(pn_data_t *data);
511 
523 PN_EXTERN int pn_data_format(pn_data_t *data, char *bytes, size_t *size);
524 
535 PN_EXTERN ssize_t pn_data_encode(pn_data_t *data, char *bytes, size_t size);
536 
544 PN_EXTERN ssize_t pn_data_encoded_size(pn_data_t *data);
545 
563 PN_EXTERN ssize_t pn_data_decode(pn_data_t *data, const char *bytes, size_t size);
564 
587 PN_EXTERN int pn_data_put_list(pn_data_t *data);
588 
607 PN_EXTERN int pn_data_put_map(pn_data_t *data);
608 
642 PN_EXTERN int pn_data_put_array(pn_data_t *data, bool described, pn_type_t type);
643 
663 PN_EXTERN int pn_data_put_described(pn_data_t *data);
664 
671 PN_EXTERN int pn_data_put_null(pn_data_t *data);
672 
680 PN_EXTERN int pn_data_put_bool(pn_data_t *data, bool b);
681 
689 PN_EXTERN int pn_data_put_ubyte(pn_data_t *data, uint8_t ub);
690 
698 PN_EXTERN int pn_data_put_byte(pn_data_t *data, int8_t b);
699 
707 PN_EXTERN int pn_data_put_ushort(pn_data_t *data, uint16_t us);
708 
716 PN_EXTERN int pn_data_put_short(pn_data_t *data, int16_t s);
717 
725 PN_EXTERN int pn_data_put_uint(pn_data_t *data, uint32_t ui);
726 
734 PN_EXTERN int pn_data_put_int(pn_data_t *data, int32_t i);
735 
743 PN_EXTERN int pn_data_put_char(pn_data_t *data, pn_char_t c);
744 
752 PN_EXTERN int pn_data_put_ulong(pn_data_t *data, uint64_t ul);
753 
761 PN_EXTERN int pn_data_put_long(pn_data_t *data, int64_t l);
762 
770 PN_EXTERN int pn_data_put_timestamp(pn_data_t *data, pn_timestamp_t t);
771 
779 PN_EXTERN int pn_data_put_float(pn_data_t *data, float f);
780 
788 PN_EXTERN int pn_data_put_double(pn_data_t *data, double d);
789 
797 PN_EXTERN int pn_data_put_decimal32(pn_data_t *data, pn_decimal32_t d);
798 
806 PN_EXTERN int pn_data_put_decimal64(pn_data_t *data, pn_decimal64_t d);
807 
815 PN_EXTERN int pn_data_put_decimal128(pn_data_t *data, pn_decimal128_t d);
816 
824 PN_EXTERN int pn_data_put_uuid(pn_data_t *data, pn_uuid_t u);
825 
834 PN_EXTERN int pn_data_put_binary(pn_data_t *data, pn_bytes_t bytes);
835 
844 PN_EXTERN int pn_data_put_string(pn_data_t *data, pn_bytes_t string);
845 
854 PN_EXTERN int pn_data_put_symbol(pn_data_t *data, pn_bytes_t symbol);
855 
863 PN_EXTERN int pn_data_put_atom(pn_data_t *data, pn_atom_t atom);
864 
892 PN_EXTERN size_t pn_data_get_list(pn_data_t *data);
893 
932 PN_EXTERN size_t pn_data_get_map(pn_data_t *data);
933 
967 PN_EXTERN size_t pn_data_get_array(pn_data_t *data);
968 
975 PN_EXTERN bool pn_data_is_array_described(pn_data_t *data);
976 
985 
1009 PN_EXTERN bool pn_data_is_described(pn_data_t *data);
1010 
1017 PN_EXTERN bool pn_data_is_null(pn_data_t *data);
1018 
1024 PN_EXTERN bool pn_data_get_bool(pn_data_t *data);
1025 
1032 PN_EXTERN uint8_t pn_data_get_ubyte(pn_data_t *data);
1033 
1040 PN_EXTERN int8_t pn_data_get_byte(pn_data_t *data);
1041 
1048 PN_EXTERN uint16_t pn_data_get_ushort(pn_data_t *data);
1049 
1056 PN_EXTERN int16_t pn_data_get_short(pn_data_t *data);
1057 
1064 PN_EXTERN uint32_t pn_data_get_uint(pn_data_t *data);
1065 
1072 PN_EXTERN int32_t pn_data_get_int(pn_data_t *data);
1073 
1080 PN_EXTERN pn_char_t pn_data_get_char(pn_data_t *data);
1081 
1088 PN_EXTERN uint64_t pn_data_get_ulong(pn_data_t *data);
1089 
1096 PN_EXTERN int64_t pn_data_get_long(pn_data_t *data);
1097 
1105 
1112 PN_EXTERN float pn_data_get_float(pn_data_t *data);
1113 
1120 PN_EXTERN double pn_data_get_double(pn_data_t *data);
1121 
1129 
1137 
1145 
1153 PN_EXTERN pn_uuid_t pn_data_get_uuid(pn_data_t *data);
1154 
1163 PN_EXTERN pn_bytes_t pn_data_get_binary(pn_data_t *data);
1164 
1174 PN_EXTERN pn_bytes_t pn_data_get_string(pn_data_t *data);
1175 
1185 PN_EXTERN pn_bytes_t pn_data_get_symbol(pn_data_t *data);
1186 
1196 PN_EXTERN pn_bytes_t pn_data_get_bytes(pn_data_t *data);
1197 
1204 PN_EXTERN pn_atom_t pn_data_get_atom(pn_data_t *data);
1205 
1214 PN_EXTERN int pn_data_copy(pn_data_t *data, pn_data_t *src);
1215 
1223 PN_EXTERN int pn_data_append(pn_data_t *data, pn_data_t *src);
1224 
1234 PN_EXTERN int pn_data_appendn(pn_data_t *data, pn_data_t *src, int limit);
1235 
1246 PN_EXTERN void pn_data_narrow(pn_data_t *data);
1247 
1253 PN_EXTERN void pn_data_widen(pn_data_t *data);
1254 
1262 PN_EXTERN pn_handle_t pn_data_point(pn_data_t *data);
1263 
1275 PN_EXTERN bool pn_data_restore(pn_data_t *data, pn_handle_t point);
1276 
1284 PN_EXTERN void pn_data_dump(pn_data_t *data);
1285 
1290 #ifdef __cplusplus
1291 }
1292 #endif
1293 
1294 #endif /* codec.h */
The unsigned int AMQP type.
Definition: codec.h:81
An AMQP map.
Definition: codec.h:175
uint32_t pn_data_get_uint(pn_data_t *data)
If the current node is an unsigned int, returns its value, returns 0 otherwise.
pn_decimal64_t pn_data_get_decimal64(pn_data_t *data)
If the current node is a decimal64, returns its value, returns 0 otherwise.
The decimal64 AMQP type.
Definition: codec.h:127
int pn_data_put_int(pn_data_t *data, int32_t i)
Puts a PN_INT value.
int pn_data_put_decimal128(pn_data_t *data, pn_decimal128_t d)
Puts a PN_DECIMAL128 value.
uint32_t pn_decimal32_t
A 32-bit decimal floating-point number.
Definition: types.h:180
int pn_data_put_bool(pn_data_t *data, bool b)
Puts a PN_BOOL value.
int pn_data_put_decimal64(pn_data_t *data, pn_decimal64_t d)
Puts a PN_DECIMAL64 value.
ssize_t pn_data_encoded_size(pn_data_t *data)
Returns the number of bytes needed to encode a data object.
AMQP and API data types.
int16_t pn_data_get_short(pn_data_t *data)
If the current node is a signed short, returns its value, returns 0 otherwise.
int pn_data_put_described(pn_data_t *data)
Puts a described value into a pn_data_t object.
int pn_data_put_binary(pn_data_t *data, pn_bytes_t bytes)
Puts a PN_BINARY value.
void pn_data_widen(pn_data_t *data)
Reverse the effect of pn_data_narrow().
pn_decimal128_t pn_data_get_decimal128(pn_data_t *data)
If the current node is a decimal128, returns its value, returns 0 otherwise.
void pn_data_narrow(pn_data_t *data)
Modify a pn_data_t object to behave as if the current node is the root node of the tree...
A 16-byte universally unique identifier.
Definition: types.h:203
int pn_data_put_double(pn_data_t *data, double d)
Puts a PN_DOUBLE value.
The float AMQP type.
Definition: codec.h:112
size_t pn_data_get_list(pn_data_t *data)
If the current node is a list, return the number of elements, otherwise return zero.
A descriminated union that holds any scalar AMQP value.
Definition: codec.h:200
The UUID AMQP type.
Definition: codec.h:137
float pn_data_get_float(pn_data_t *data)
If the current node is a float, returns its value, raises 0 otherwise.
The NULL AMQP type.
Definition: codec.h:51
pn_bytes_t pn_data_get_bytes(pn_data_t *data)
If the current node is a symbol, string, or binary, return the bytes representing its value...
uint8_t pn_data_get_ubyte(pn_data_t *data)
If the current node is a PN_UBYTE, return its value, otherwise return 0.
bool pn_data_is_array_described(pn_data_t *data)
Returns true if the current node points to a described array.
pn_uuid_t pn_data_get_uuid(pn_data_t *data)
If the current node is a UUID, returns its value, returns None otherwise.
int pn_data_put_list(pn_data_t *data)
Puts an empty list value into a pn_data_t.
size_t pn_data_size(pn_data_t *data)
Returns the total number of nodes contained in a pn_data_t object.
int8_t pn_data_get_byte(pn_data_t *data)
If the current node is a signed byte, returns its value, returns 0 otherwise.
The byte AMQP type.
Definition: codec.h:66
bool pn_data_get_bool(pn_data_t *data)
If the current node is a PN_BOOL, returns its value.
The timestamp AMQP type.
Definition: codec.h:107
An AMQP array.
Definition: codec.h:164
The double AMQP type.
Definition: codec.h:117
int pn_data_print(pn_data_t *data)
Prints the contents of a pn_data_t object using pn_data_format() to stdout.
struct pn_error_t pn_error_t
An int error code and some string text to describe the error.
Definition: error.h:44
pn_type_t pn_data_get_array_type(pn_data_t *data)
Return the array type if the current node points to an array, PN_INVALID otherwise.
The string AMQP type.
Definition: codec.h:148
int pn_data_put_char(pn_data_t *data, pn_char_t c)
Puts a PN_CHAR value.
pn_handle_t pn_data_point(pn_data_t *data)
Returns a handle for the current navigational state of a pn_data_t so that it can be later restored u...
int32_t pn_data_get_int(pn_data_t *data)
If the current node is a signed int, returns its value, returns 0 otherwise.
bool pn_data_prev(pn_data_t *data)
Moves the current node to its previous sibling and returns true.
A Proton API error.
uint64_t pn_data_get_ulong(pn_data_t *data)
If the current node is an unsigned long, returns its value, returns 0 otherwise.
The char AMQP type.
Definition: codec.h:91
void pn_data_dump(pn_data_t *data)
Dumps a debug representation of the internal state of the pn_data_t object that includes its navigati...
int pn_data_put_ulong(pn_data_t *data, uint64_t ul)
Puts a PN_ULONG value.
An AMQP list.
Definition: codec.h:169
The ulong AMQP type.
Definition: codec.h:96
The symbol AMQP type.
Definition: codec.h:154
double pn_data_get_double(pn_data_t *data)
If the current node is a double, returns its value, returns 0 otherwise.
bool pn_data_next(pn_data_t *data)
Advances the current node to its next sibling and returns true.
int pn_data_put_null(pn_data_t *data)
Puts a PN_NULL value.
int pn_data_errno(pn_data_t *data)
Access the current error code for a given pn_data_t.
int pn_data_format(pn_data_t *data, char *bytes, size_t *size)
Formats the contents of a pn_data_t object in a human readable way and writes them to the indicated l...
The signed int AMQP type.
Definition: codec.h:86
void pn_data_rewind(pn_data_t *data)
Clears current node pointer and sets the parent to the root node.
pn_decimal32_t pn_data_get_decimal32(pn_data_t *data)
If the current node is a decimal32, returns its value, returns 0 otherwise.
int pn_data_put_short(pn_data_t *data, int16_t s)
Puts a PN_SHORT value.
A 128-bit decimal floating-point number.
Definition: types.h:194
int pn_data_put_array(pn_data_t *data, bool described, pn_type_t type)
Puts an empty array value into a pn_data_t.
pn_bytes_t pn_data_get_binary(pn_data_t *data)
If the current node is binary, returns its value, returns "" otherwise.
pn_error_t * pn_data_error(pn_data_t *data)
Access the current error for a givn pn_data_t.
pn_atom_t pn_data_get_atom(pn_data_t *data)
If the current node is a scalar value, return it as a pn_atom_t.
pn_bytes_t pn_data_get_string(pn_data_t *data)
If the current node is a string, returns its value, returns "" otherwise.
void pn_data_free(pn_data_t *data)
Free a pn_data_t object.
uint64_t pn_decimal64_t
A 64-bit decimal floating-point number.
Definition: types.h:187
pn_bytes_t pn_data_get_symbol(pn_data_t *data)
If the current node is a symbol, returns its value, returns "" otherwise.
int pn_data_put_timestamp(pn_data_t *data, pn_timestamp_t t)
Puts a PN_TIMESTAMP value.
int pn_data_put_uint(pn_data_t *data, uint32_t ui)
Puts a PN_UINT value.
int64_t pn_data_get_long(pn_data_t *data)
If the current node is an signed long, returns its value, returns 0 otherwise.
struct pn_data_t pn_data_t
An AMQP Data object.
Definition: codec.h:364
The decimal128 AMQP type.
Definition: codec.h:132
bool pn_data_restore(pn_data_t *data, pn_handle_t point)
Restores a prior navigational state that was saved using pn_data_point().
int pn_data_put_float(pn_data_t *data, float f)
Puts a PN_FLOAT value.
ssize_t pn_data_decode(pn_data_t *data, const char *bytes, size_t size)
Decodes a single value from the contents of the AMQP data stream into the current data object...
int pn_data_appendn(pn_data_t *data, pn_data_t *src, int limit)
Append up to n values from the contents of another pn_data_t object.
int pn_data_put_decimal32(pn_data_t *data, pn_decimal32_t d)
Puts a PN_DECIMAL32 value.
uint32_t pn_char_t
A 32-bit Unicode code point.
Definition: types.h:173
size_t pn_data_get_map(pn_data_t *data)
If the current node is a map, return the number of child elements, otherwise return zero...
size_t pn_data_get_array(pn_data_t *data)
If the current node is an array, return the number of elements in the array, otherwise return 0...
const char * pn_type_name(pn_type_t type)
Return a string name for an AMQP type.
The long AMQP type.
Definition: codec.h:101
int pn_data_copy(pn_data_t *data, pn_data_t *src)
Copy the contents of another pn_data_t object.
The unsigned byte AMQP type.
Definition: codec.h:61
A special invalid type value that is returned when no valid type is available.
Definition: codec.h:181
A described AMQP type.
Definition: codec.h:159
bool pn_data_enter(pn_data_t *data)
Sets the parent node to the current node and clears the current node.
int pn_data_put_long(pn_data_t *data, int64_t l)
Puts a PN_LONG value.
The short AMQP type.
Definition: codec.h:76
int pn_data_put_map(pn_data_t *data)
Puts an empty map value into a pn_data_t.
int pn_data_put_symbol(pn_data_t *data, pn_bytes_t symbol)
Puts a PN_SYMBOL value.
int pn_data_put_uuid(pn_data_t *data, pn_uuid_t u)
Puts a PN_UUID value.
pn_type_t pn_data_type(pn_data_t *data)
Access the type of the current node.
pn_data_t * pn_data(size_t capacity)
Construct a pn_data_t object with the supplied initial capacity.
The binary AMQP type.
Definition: codec.h:142
int pn_data_put_string(pn_data_t *data, pn_bytes_t string)
Puts a PN_STRING value.
pn_timestamp_t pn_data_get_timestamp(pn_data_t *data)
If the current node is a timestamp, returns its value, returns 0 otherwise.
pn_char_t pn_data_get_char(pn_data_t *data)
If the current node is a char, returns its value, returns 0 otherwise.
pn_type_t
Identifies an AMQP type.
Definition: codec.h:47
int pn_data_put_ushort(pn_data_t *data, uint16_t us)
Puts a PN_USHORT value.
The boolean AMQP type.
Definition: codec.h:56
bool pn_data_exit(pn_data_t *data)
Sets the current node to the parent node and the parent node to its own parent.
void pn_data_clear(pn_data_t *data)
Clears a pn_data_t object.
uint16_t pn_data_get_ushort(pn_data_t *data)
If the current node is an unsigned short, returns its value, returns 0 otherwise. ...
The decimal32 AMQP type.
Definition: codec.h:122
ssize_t pn_data_encode(pn_data_t *data, char *bytes, size_t size)
Writes the contents of a data object to the given buffer as an AMQP data stream.
bool pn_data_is_null(pn_data_t *data)
Checks if the current node is a PN_NULL.
int pn_data_append(pn_data_t *data, pn_data_t *src)
Append the contents of another pn_data_t object.
A const byte buffer.
Definition: types.h:212
int pn_data_put_ubyte(pn_data_t *data, uint8_t ub)
Puts a PN_UBYTE value.
pn_type_t type
Indicates the type of value the atom is currently pointing to.
Definition: codec.h:205
int64_t pn_timestamp_t
A 64-bit timestamp in milliseconds since the Unix epoch.
Definition: types.h:166
int pn_data_put_byte(pn_data_t *data, int8_t b)
Puts a PN_BYTE value.
bool pn_data_is_described(pn_data_t *data)
Checks if the current node is a described value.
int pn_data_put_atom(pn_data_t *data, pn_atom_t atom)
Puts any scalar value value.
The unsigned short AMQP type.
Definition: codec.h:71