codec.h
Go to the documentation of this file.
#ifndef PROTON_CODEC_H
#define PROTON_CODEC_H 1
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
#include <proton/import_export.h>
#include <proton/object.h>
#include <proton/types.h>
#include <proton/error.h>
#include <proton/type_compat.h>
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
PN_NULL = 1,
PN_BOOL = 2,
PN_UBYTE = 3,
PN_BYTE = 4,
PN_USHORT = 5,
PN_SHORT = 6,
PN_UINT = 7,
PN_INT = 8,
PN_CHAR = 9,
PN_ULONG = 10,
PN_LONG = 11,
PN_TIMESTAMP = 12,
PN_FLOAT = 13,
PN_DOUBLE = 14,
PN_DECIMAL32 = 15,
PN_DECIMAL64 = 16,
PN_DECIMAL128 = 17,
PN_UUID = 18,
PN_BINARY = 19,
PN_STRING = 20,
PN_SYMBOL = 21,
PN_DESCRIBED = 22,
PN_ARRAY = 23,
PN_LIST = 24,
PN_MAP = 25,
PN_INVALID = -1
} pn_type_t;
PN_EXTERN const char *pn_type_name(pn_type_t type);
typedef struct {
pn_type_t type;
union {
bool as_bool;
uint8_t as_ubyte;
int8_t as_byte;
uint16_t as_ushort;
int16_t as_short;
uint32_t as_uint;
int32_t as_int;
pn_char_t as_char;
uint64_t as_ulong;
int64_t as_long;
pn_timestamp_t as_timestamp;
float as_float;
double as_double;
pn_decimal32_t as_decimal32;
pn_decimal64_t as_decimal64;
pn_decimal128_t as_decimal128;
pn_uuid_t as_uuid;
pn_bytes_t as_bytes;
} u;
} pn_atom_t;
typedef struct pn_data_t pn_data_t;
PN_EXTERN pn_data_t *pn_data(size_t capacity);
PN_EXTERN void pn_data_free(pn_data_t *data);
PN_EXTERN int pn_data_errno(pn_data_t *data);
PN_EXTERN pn_error_t *pn_data_error(pn_data_t *data);
PN_EXTERN int pn_data_vfill(pn_data_t *data, const char *fmt, va_list ap);
PN_EXTERN int pn_data_fill(pn_data_t *data, const char *fmt, ...);
PN_EXTERN int pn_data_vscan(pn_data_t *data, const char *fmt, va_list ap);
PN_EXTERN int pn_data_scan(pn_data_t *data, const char *fmt, ...);
PN_EXTERN void pn_data_clear(pn_data_t *data);
PN_EXTERN size_t pn_data_size(pn_data_t *data);
PN_EXTERN void pn_data_rewind(pn_data_t *data);
PN_EXTERN bool pn_data_next(pn_data_t *data);
PN_EXTERN bool pn_data_prev(pn_data_t *data);
PN_EXTERN bool pn_data_enter(pn_data_t *data);
PN_EXTERN bool pn_data_exit(pn_data_t *data);
PN_EXTERN bool pn_data_lookup(pn_data_t *data, const char *name);
PN_EXTERN pn_type_t pn_data_type(pn_data_t *data);
PN_EXTERN int pn_data_print(pn_data_t *data);
PN_EXTERN int pn_data_format(pn_data_t *data, char *bytes, size_t *size);
PN_EXTERN ssize_t pn_data_encode(pn_data_t *data, char *bytes, size_t size);
PN_EXTERN ssize_t pn_data_encoded_size(pn_data_t *data);
PN_EXTERN ssize_t pn_data_decode(pn_data_t *data, const char *bytes, size_t size);
PN_EXTERN int pn_data_put_list(pn_data_t *data);
PN_EXTERN int pn_data_put_map(pn_data_t *data);
PN_EXTERN int pn_data_put_array(pn_data_t *data, bool described, pn_type_t type);
PN_EXTERN int pn_data_put_described(pn_data_t *data);
PN_EXTERN int pn_data_put_null(pn_data_t *data);
PN_EXTERN int pn_data_put_bool(pn_data_t *data, bool b);
PN_EXTERN int pn_data_put_ubyte(pn_data_t *data, uint8_t ub);
PN_EXTERN int pn_data_put_byte(pn_data_t *data, int8_t b);
PN_EXTERN int pn_data_put_ushort(pn_data_t *data, uint16_t us);
PN_EXTERN int pn_data_put_short(pn_data_t *data, int16_t s);
PN_EXTERN int pn_data_put_uint(pn_data_t *data, uint32_t ui);
PN_EXTERN int pn_data_put_int(pn_data_t *data, int32_t i);
PN_EXTERN int pn_data_put_char(pn_data_t *data, pn_char_t c);
PN_EXTERN int pn_data_put_ulong(pn_data_t *data, uint64_t ul);
PN_EXTERN int pn_data_put_long(pn_data_t *data, int64_t l);
PN_EXTERN int pn_data_put_timestamp(pn_data_t *data, pn_timestamp_t t);
PN_EXTERN int pn_data_put_float(pn_data_t *data, float f);
PN_EXTERN int pn_data_put_double(pn_data_t *data, double d);
PN_EXTERN int pn_data_put_decimal32(pn_data_t *data, pn_decimal32_t d);
PN_EXTERN int pn_data_put_decimal64(pn_data_t *data, pn_decimal64_t d);
PN_EXTERN int pn_data_put_decimal128(pn_data_t *data, pn_decimal128_t d);
PN_EXTERN int pn_data_put_uuid(pn_data_t *data, pn_uuid_t u);
PN_EXTERN int pn_data_put_binary(pn_data_t *data, pn_bytes_t bytes);
PN_EXTERN int pn_data_put_string(pn_data_t *data, pn_bytes_t string);
PN_EXTERN int pn_data_put_symbol(pn_data_t *data, pn_bytes_t symbol);
PN_EXTERN int pn_data_put_atom(pn_data_t *data, pn_atom_t atom);
PN_EXTERN size_t pn_data_get_list(pn_data_t *data);
PN_EXTERN size_t pn_data_get_map(pn_data_t *data);
PN_EXTERN size_t pn_data_get_array(pn_data_t *data);
PN_EXTERN bool pn_data_is_array_described(pn_data_t *data);
PN_EXTERN pn_type_t pn_data_get_array_type(pn_data_t *data);
PN_EXTERN bool pn_data_is_described(pn_data_t *data);
PN_EXTERN bool pn_data_is_null(pn_data_t *data);
PN_EXTERN bool pn_data_get_bool(pn_data_t *data);
PN_EXTERN uint8_t pn_data_get_ubyte(pn_data_t *data);
PN_EXTERN int8_t pn_data_get_byte(pn_data_t *data);
PN_EXTERN uint16_t pn_data_get_ushort(pn_data_t *data);
PN_EXTERN int16_t pn_data_get_short(pn_data_t *data);
PN_EXTERN uint32_t pn_data_get_uint(pn_data_t *data);
PN_EXTERN int32_t pn_data_get_int(pn_data_t *data);
PN_EXTERN pn_char_t pn_data_get_char(pn_data_t *data);
PN_EXTERN uint64_t pn_data_get_ulong(pn_data_t *data);
PN_EXTERN int64_t pn_data_get_long(pn_data_t *data);
PN_EXTERN pn_timestamp_t pn_data_get_timestamp(pn_data_t *data);
PN_EXTERN float pn_data_get_float(pn_data_t *data);
PN_EXTERN double pn_data_get_double(pn_data_t *data);
PN_EXTERN pn_decimal32_t pn_data_get_decimal32(pn_data_t *data);
PN_EXTERN pn_decimal64_t pn_data_get_decimal64(pn_data_t *data);
PN_EXTERN pn_decimal128_t pn_data_get_decimal128(pn_data_t *data);
PN_EXTERN pn_uuid_t pn_data_get_uuid(pn_data_t *data);
PN_EXTERN pn_bytes_t pn_data_get_binary(pn_data_t *data);
PN_EXTERN pn_bytes_t pn_data_get_string(pn_data_t *data);
PN_EXTERN pn_bytes_t pn_data_get_symbol(pn_data_t *data);
PN_EXTERN pn_bytes_t pn_data_get_bytes(pn_data_t *data);
PN_EXTERN pn_atom_t pn_data_get_atom(pn_data_t *data);
PN_EXTERN int pn_data_copy(pn_data_t *data, pn_data_t *src);
PN_EXTERN int pn_data_append(pn_data_t *data, pn_data_t *src);
PN_EXTERN int pn_data_appendn(pn_data_t *data, pn_data_t *src, int limit);
PN_EXTERN void pn_data_narrow(pn_data_t *data);
PN_EXTERN void pn_data_widen(pn_data_t *data);
PN_EXTERN pn_handle_t pn_data_point(pn_data_t *data);
PN_EXTERN bool pn_data_restore(pn_data_t *data, pn_handle_t point);
PN_EXTERN void pn_data_dump(pn_data_t *data);
#ifdef __cplusplus
}
#endif
#endif /* codec.h */
pn_data_get_decimal32
pn_decimal32_t pn_data_get_decimal32(pn_data_t *data)
If the current node is a decimal32, returns its value, returns 0 otherwise.
pn_data_put_map
int pn_data_put_map(pn_data_t *data)
Puts an empty map value into a pn_data_t.
PN_DESCRIBED
A described AMQP type.
Definition: codec.h:159
pn_data_get_atom
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_data_widen
void pn_data_widen(pn_data_t *data)
Reverse the effect of pn_data_narrow().
pn_data_get_decimal128
pn_decimal128_t pn_data_get_decimal128(pn_data_t *data)
If the current node is a decimal128, returns its value, returns 0 otherwise.
PN_UINT
The unsigned int AMQP type.
Definition: codec.h:81
PN_USHORT
The unsigned short AMQP type.
Definition: codec.h:71
pn_type_t
pn_type_t
Identifies an AMQP type.
Definition: codec.h:47
PN_ULONG
The ulong AMQP type.
Definition: codec.h:96
pn_data_get_bytes
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.
pn_data_put_timestamp
int pn_data_put_timestamp(pn_data_t *data, pn_timestamp_t t)
Puts a PN_TIMESTAMP value.
pn_data_get_uuid
pn_uuid_t pn_data_get_uuid(pn_data_t *data)
If the current node is a UUID, returns its value, returns None otherwise.
pn_data_put_char
int pn_data_put_char(pn_data_t *data, pn_char_t c)
Puts a PN_CHAR value.
types.h
pn_data_put_long
int pn_data_put_long(pn_data_t *data, int64_t l)
Puts a PN_LONG value.
PN_DECIMAL64
The decimal64 AMQP type.
Definition: codec.h:127
pn_data_type
pn_type_t pn_data_type(pn_data_t *data)
Access the type of the current node.
pn_data_get_double
double pn_data_get_double(pn_data_t *data)
If the current node is a double, returns its value, returns 0 otherwise.
pn_data_is_null
bool pn_data_is_null(pn_data_t *data)
Checks if the current node is a PN_NULL.
pn_data_append
int pn_data_append(pn_data_t *data, pn_data_t *src)
Append the contents of another pn_data_t object.
pn_error_t
struct pn_error_t pn_error_t
An int error code and some string text to describe the error.
Definition: error.h:44
pn_data_put_decimal64
int pn_data_put_decimal64(pn_data_t *data, pn_decimal64_t d)
Puts a PN_DECIMAL64 value.
pn_data_put_decimal32
int pn_data_put_decimal32(pn_data_t *data, pn_decimal32_t d)
Puts a PN_DECIMAL32 value.
pn_data_get_array
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.
pn_data_get_short
int16_t pn_data_get_short(pn_data_t *data)
If the current node is a signed short, returns its value, returns 0 otherwise.
pn_data_get_binary
pn_bytes_t pn_data_get_binary(pn_data_t *data)
If the current node is binary, returns its value, returns "" otherwise.
pn_data_put_binary
int pn_data_put_binary(pn_data_t *data, pn_bytes_t bytes)
Puts a PN_BINARY value.
pn_data_print
int pn_data_print(pn_data_t *data)
Prints the contents of a pn_data_t object using pn_data_format() to stdout.
pn_type_name
const char * pn_type_name(pn_type_t type)
Return a string name for an AMQP type.
pn_data_dump
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...
pn_atom_t
A discriminated union that holds any scalar AMQP value.
Definition: codec.h:200
pn_data_put_decimal128
int pn_data_put_decimal128(pn_data_t *data, pn_decimal128_t d)
Puts a PN_DECIMAL128 value.
PN_STRING
The string AMQP type.
Definition: codec.h:148
pn_data_rewind
void pn_data_rewind(pn_data_t *data)
Clears current node pointer and sets the parent to the root node.
pn_data_get_ubyte
uint8_t pn_data_get_ubyte(pn_data_t *data)
If the current node is a PN_UBYTE, return its value, otherwise return 0.
PN_INVALID
A special invalid type value that is returned when no valid type is available.
Definition: codec.h:181
pn_data_is_described
bool pn_data_is_described(pn_data_t *data)
Checks if the current node is a described value.
pn_atom_t::type
pn_type_t type
Indicates the type of value the atom is currently pointing to.
Definition: codec.h:205
PN_UUID
The UUID AMQP type.
Definition: codec.h:137
pn_data_prev
bool pn_data_prev(pn_data_t *data)
Moves the current node to its previous sibling and returns true.
PN_INT
The signed int AMQP type.
Definition: codec.h:86
pn_data_put_array
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_data_get_uint
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_BYTE
The byte AMQP type.
Definition: codec.h:66
pn_data_get_ulong
uint64_t pn_data_get_ulong(pn_data_t *data)
If the current node is an unsigned long, returns its value, returns 0 otherwise.
pn_data_encoded_size
ssize_t pn_data_encoded_size(pn_data_t *data)
Returns the number of bytes needed to encode a data object.
pn_data_get_array_type
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.
pn_decimal32_t
uint32_t pn_decimal32_t
A 32-bit decimal floating-point number.
Definition: types.h:180
PN_MAP
An AMQP map.
Definition: codec.h:175
pn_data_put_described
int pn_data_put_described(pn_data_t *data)
Puts a described value into a pn_data_t object.
pn_data_encode
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.
pn_bytes_t
A const byte buffer.
Definition: types.h:212
pn_data_put_null
int pn_data_put_null(pn_data_t *data)
Puts a PN_NULL value.
pn_data_narrow
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.
PN_NULL
The NULL AMQP type.
Definition: codec.h:51
pn_data_get_string
pn_bytes_t pn_data_get_string(pn_data_t *data)
If the current node is a string, returns its value, returns "" otherwise.
pn_char_t
uint32_t pn_char_t
A 32-bit Unicode code point.
Definition: types.h:173
PN_BOOL
The boolean AMQP type.
Definition: codec.h:56
pn_data_get_symbol
pn_bytes_t pn_data_get_symbol(pn_data_t *data)
If the current node is a symbol, returns its value, returns "" otherwise.
pn_data_get_float
float pn_data_get_float(pn_data_t *data)
If the current node is a float, returns its value, raises 0 otherwise.
pn_data_t
struct pn_data_t pn_data_t
An AMQP Data object.
Definition: codec.h:364
pn_data_size
size_t pn_data_size(pn_data_t *data)
Returns the total number of nodes contained in a pn_data_t object.
pn_data_decode
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.
pn_data_put_int
int pn_data_put_int(pn_data_t *data, int32_t i)
Puts a PN_INT value.
PN_DOUBLE
The double AMQP type.
Definition: codec.h:117
pn_data_put_bool
int pn_data_put_bool(pn_data_t *data, bool b)
Puts a PN_BOOL value.
error.h
pn_data_get_timestamp
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_data_get_char
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_UBYTE
The unsigned byte AMQP type.
Definition: codec.h:61
pn_data_enter
bool pn_data_enter(pn_data_t *data)
Sets the parent node to the current node and clears the current node.
pn_data_put_uint
int pn_data_put_uint(pn_data_t *data, uint32_t ui)
Puts a PN_UINT value.
pn_data_get_int
int32_t pn_data_get_int(pn_data_t *data)
If the current node is a signed int, returns its value, returns 0 otherwise.
PN_DECIMAL32
The decimal32 AMQP type.
Definition: codec.h:122
pn_data_next
bool pn_data_next(pn_data_t *data)
Advances the current node to its next sibling and returns true.
pn_timestamp_t
int64_t pn_timestamp_t
A 64-bit timestamp in milliseconds since the Unix epoch.
Definition: types.h:166
pn_data_appendn
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.
pn_data_get_list
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.
pn_data_is_array_described
bool pn_data_is_array_described(pn_data_t *data)
Returns true if the current node points to a described array.
pn_data_point
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...
pn_data_copy
int pn_data_copy(pn_data_t *data, pn_data_t *src)
Copy the contents of another pn_data_t object.
PN_CHAR
The char AMQP type.
Definition: codec.h:91
PN_LIST
An AMQP list.
Definition: codec.h:169
pn_data_error
pn_error_t * pn_data_error(pn_data_t *data)
Access the current error for a given pn_data_t.
pn_data_get_byte
int8_t pn_data_get_byte(pn_data_t *data)
If the current node is a signed byte, returns its value, returns 0 otherwise.
pn_data_put_string
int pn_data_put_string(pn_data_t *data, pn_bytes_t string)
Puts a PN_STRING value.
PN_BINARY
The binary AMQP type.
Definition: codec.h:142
pn_data_get_map
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.
pn_data_put_atom
int pn_data_put_atom(pn_data_t *data, pn_atom_t atom)
Puts any scalar value value.
pn_uuid_t
A 16-byte universally unique identifier.
Definition: types.h:203
pn_data_get_long
int64_t pn_data_get_long(pn_data_t *data)
If the current node is an signed long, returns its value, returns 0 otherwise.
pn_data_put_short
int pn_data_put_short(pn_data_t *data, int16_t s)
Puts a PN_SHORT value.
pn_data_put_uuid
int pn_data_put_uuid(pn_data_t *data, pn_uuid_t u)
Puts a PN_UUID value.
pn_data_get_ushort
uint16_t pn_data_get_ushort(pn_data_t *data)
If the current node is an unsigned short, returns its value, returns 0 otherwise.
pn_data_get_decimal64
pn_decimal64_t pn_data_get_decimal64(pn_data_t *data)
If the current node is a decimal64, returns its value, returns 0 otherwise.
pn_data_restore
bool pn_data_restore(pn_data_t *data, pn_handle_t point)
Restores a prior navigational state that was saved using pn_data_point().
pn_data_put_double
int pn_data_put_double(pn_data_t *data, double d)
Puts a PN_DOUBLE value.
pn_data_format
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...
PN_DECIMAL128
The decimal128 AMQP type.
Definition: codec.h:132
pn_data_put_ubyte
int pn_data_put_ubyte(pn_data_t *data, uint8_t ub)
Puts a PN_UBYTE value.
pn_data_put_ushort
int pn_data_put_ushort(pn_data_t *data, uint16_t us)
Puts a PN_USHORT value.
PN_SHORT
The short AMQP type.
Definition: codec.h:76
PN_LONG
The long AMQP type.
Definition: codec.h:101
pn_data_put_symbol
int pn_data_put_symbol(pn_data_t *data, pn_bytes_t symbol)
Puts a PN_SYMBOL value.
pn_data_clear
void pn_data_clear(pn_data_t *data)
Clears a pn_data_t object.
pn_data_exit
bool pn_data_exit(pn_data_t *data)
Sets the current node to the parent node and the parent node to its own parent.
pn_data_put_list
int pn_data_put_list(pn_data_t *data)
Puts an empty list value into a pn_data_t.
pn_data_get_bool
bool pn_data_get_bool(pn_data_t *data)
If the current node is a PN_BOOL, returns its value.
PN_TIMESTAMP
The timestamp AMQP type.
Definition: codec.h:107
pn_data
pn_data_t * pn_data(size_t capacity)
Construct a pn_data_t object with the supplied initial capacity.
PN_FLOAT
The float AMQP type.
Definition: codec.h:112
pn_data_put_ulong
int pn_data_put_ulong(pn_data_t *data, uint64_t ul)
Puts a PN_ULONG value.
pn_data_put_byte
int pn_data_put_byte(pn_data_t *data, int8_t b)
Puts a PN_BYTE value.
PN_SYMBOL
The symbol AMQP type.
Definition: codec.h:154
pn_data_free
void pn_data_free(pn_data_t *data)
Free a pn_data_t object.
pn_decimal64_t
uint64_t pn_decimal64_t
A 64-bit decimal floating-point number.
Definition: types.h:187
pn_decimal128_t
A 128-bit decimal floating-point number.
Definition: types.h:194
pn_data_put_float
int pn_data_put_float(pn_data_t *data, float f)
Puts a PN_FLOAT value.
pn_data_errno
int pn_data_errno(pn_data_t *data)
Access the current error code for a given pn_data_t.
PN_ARRAY
An AMQP array.
Definition: codec.h:164