MsgPuck is a simple and efficient MsgPack encoder/decoder library in a single self-contained file.
More...
|
| __attribute__ ((pure)) enum mp_type mp_typeof(const char c) |
| Determine MsgPack type by a first byte c of encoded data. More...
|
|
| __attribute__ ((const)) uint32_t mp_sizeof_array(uint32_t size) |
| Calculate exact buffer size needed to store an array header of size elements. Maximum return value is 5. For performance reasons you can preallocate buffer for maximum size without calling the function. More...
|
|
char * | mp_encode_array (char *data, uint32_t size) |
| Encode an array header of size elements. More...
|
|
uint32_t | mp_decode_array (const char **data) |
| Decode an array header from MsgPack data. More...
|
|
char * | mp_encode_map (char *data, uint32_t size) |
| Encode a map header of size elements. More...
|
|
uint32_t | mp_decode_map (const char **data) |
| Decode a map header from MsgPack data. More...
|
|
char * | mp_encode_uint (char *data, uint64_t num) |
| Encode an unsigned integer num. It is your responsibility to ensure that data has enough space. More...
|
|
char * | mp_encode_int (char *data, int64_t num) |
| Encode a signed integer num. It is your responsibility to ensure that data has enough space. More...
|
|
uint64_t | mp_decode_uint (const char **data) |
| Decode an unsigned integer from MsgPack data. More...
|
|
int64_t | mp_decode_int (const char **data) |
| Decode a signed integer from MsgPack data. More...
|
|
char * | mp_encode_float (char *data, float num) |
| Encode a float num. It is your responsibility to ensure that data has enough space. More...
|
|
char * | mp_encode_double (char *data, double num) |
| Encode a double num. It is your responsibility to ensure that data has enough space. More...
|
|
float | mp_decode_float (const char **data) |
| Decode a float from MsgPack data. More...
|
|
double | mp_decode_double (const char **data) |
| Decode a double from MsgPack data. More...
|
|
char * | mp_encode_strl (char *data, uint32_t len) |
| Encode a string header of length len. More...
|
|
char * | mp_encode_str (char *data, const char *str, uint32_t len) |
| Encode a string of length len. The function is equivalent to mp_encode_strl() + memcpy. More...
|
|
char * | mp_encode_binl (char *data, uint32_t len) |
| Encode a binstring header of length len. See mp_encode_strl() for more details. More...
|
|
char * | mp_encode_bin (char *data, const char *str, uint32_t len) |
| Encode a binstring of length len. The function is equivalent to mp_encode_binl() + memcpy. More...
|
|
size_t | mp_format (char *data, size_t data_size, const char *format,...) |
| Encode a sequence of values according to format string. Example: mp_format(buf, sz, "[%d {%d%s%d%s}]", 42, 0, "false", 1, "true"); to get a msgpack array of two items: number 42 and map (0->"false, 2->"true") Does not write items that don't fit to data_size argument. More...
|
|
size_t | mp_vformat (char *data, size_t data_size, const char *format, va_list args) |
| mp_format variation, taking variable argument list Example: va_list args; va_start(args, fmt); mp_vformat(data, data_size, fmt, args); va_end(args); More...
|
|
uint32_t | mp_decode_strl (const char **data) |
| Decode a length of a string from MsgPack data. More...
|
|
const char * | mp_decode_str (const char **data, uint32_t *len) |
| Decode a string from MsgPack data. More...
|
|
uint32_t | mp_decode_binl (const char **data) |
| Decode a length of a binstring from MsgPack data. More...
|
|
const char * | mp_decode_bin (const char **data, uint32_t *len) |
| Decode a binstring from MsgPack data. More...
|
|
char * | mp_encode_nil (char *data) |
| Encode the nil value. It is your responsibility to ensure that data has enough space. More...
|
|
void | mp_decode_nil (const char **data) |
| Decode the nil value from MsgPack data. More...
|
|
char * | mp_encode_bool (char *data, bool val) |
| Encode a bool value val. It is your responsibility to ensure that data has enough space. More...
|
|
bool | mp_decode_bool (const char **data) |
| Decode a bool value from MsgPack data. More...
|
|
void | mp_next (const char **data) |
| Skip one element in a packed data. More...
|
|
int | mp_check (const char **data, const char *end) |
| Equivalent to mp_next() but also validates MsgPack in data. More...
|
|
MsgPuck is a simple and efficient MsgPack encoder/decoder library in a single self-contained file.
MsgPuck Usage example:
char buf[1024];
char *w = buf;
const char *b = buf;
assert(!r)
assert(b == w);
uint32_t size;
uint64_t ival;
const char *sval;
uint32_t sval_len;
bool bval;
double dval;
const char *r = buf;
assert(r == w);
- Note
- Supported compilers. The implementation requires a C99+ or C++03+ compatible compiler.
-
Inline functions. The implementation is compatible with both C99 and GNU inline functions. Please define MP_SOURCE 1 before #include <msgpuck.h> in a single compilation unit. This module will be used to store non-inlined versions of functions and global tables.
__attribute__ |
( |
(pure) |
| ) |
const |
Determine MsgPack type by a first byte c of encoded data.
Check that cur buffer has enough bytes to decode a bool value.
Check that cur buffer has enough bytes to decode nil.
Check that cur buffer has enough bytes to decode a binstring header.
Check that cur buffer has enough bytes to decode a string header.
Check that cur buffer has enough bytes to decode a double.
Check that cur buffer has enough bytes to decode a float.
Compare two packed unsigned integers.
Check that cur buffer has enough bytes to decode an int.
Check that cur buffer has enough bytes to decode an uint.
Check that cur buffer has enough bytes to decode a map header.
Check that cur buffer has enough bytes to decode an array header.
Example usage:
1 assert(MP_ARRAY == mp_typeof(0x90));
- Parameters
-
c | - a first byte of encoded data |
- Returns
- MsgPack type
- Parameters
-
cur | buffer |
end | end of the buffer |
- Return values
-
0 | - buffer has enough bytes |
> | 0 - the number of remaining bytes to read |
- Precondition
- cur < end
-
mp_typeof(*cur) == MP_ARRAY
- Parameters
-
cur | buffer |
end | end of the buffer |
- Return values
-
0 | - buffer has enough bytes |
> | 0 - the number of remaining bytes to read |
- Precondition
- cur < end
-
mp_typeof(*cur) == MP_MAP
- Parameters
-
cur | buffer |
end | end of the buffer |
- Return values
-
0 | - buffer has enough bytes |
> | 0 - the number of remaining bytes to read |
- Precondition
- cur < end
-
mp_typeof(*cur) == MP_UINT
- Parameters
-
cur | buffer |
end | end of the buffer |
- Return values
-
0 | - buffer has enough bytes |
> | 0 - the number of remaining bytes to read |
- Precondition
- cur < end
-
mp_typeof(*cur) == MP_INT
The function is faster than two mp_decode_uint() calls.
- Parameters
-
data_a | unsigned int a |
data_b | unsigned int b |
- Return values
-
< | 0 when a < b |
0 | when a == b |
> | 0 when a > b |
- Parameters
-
cur | buffer |
end | end of the buffer |
- Return values
-
0 | - buffer has enough bytes |
> | 0 - the number of remaining bytes to read |
- Precondition
- cur < end
-
mp_typeof(*cur) == MP_FLOAT
- Parameters
-
cur | buffer |
end | end of the buffer |
- Return values
-
0 | - buffer has enough bytes |
> | 0 - the number of remaining bytes to read |
- Precondition
- cur < end
-
mp_typeof(*cur) == MP_DOUBLE
- Parameters
-
cur | buffer |
end | end of the buffer |
- Return values
-
0 | - buffer has enough bytes |
> | 0 - the number of remaining bytes to read |
- Precondition
- cur < end
-
mp_typeof(*cur) == MP_STR
- Parameters
-
cur | buffer |
end | end of the buffer |
- Return values
-
0 | - buffer has enough bytes |
> | 0 - the number of remaining bytes to read |
- Precondition
- cur < end
-
mp_typeof(*cur) == MP_BIN
- Parameters
-
cur | buffer |
end | end of the buffer |
- Return values
-
0 | - buffer has enough bytes |
> | 0 - the number of remaining bytes to read |
- Precondition
- cur < end
-
mp_typeof(*cur) == MP_NIL
- Parameters
-
cur | buffer |
end | end of the buffer |
- Return values
-
0 | - buffer has enough bytes |
> | 0 - the number of remaining bytes to read |
- Precondition
- cur < end
-
mp_typeof(*cur) == MP_BOOL
__attribute__ |
( |
(const) |
| ) |
|
Calculate exact buffer size needed to store an array header of size elements. Maximum return value is 5. For performance reasons you can preallocate buffer for maximum size without calling the function.
Calculate exact buffer size needed to store a boolean value. The return value is always 1. The function was added to provide integrity of the library.
Calculate exact buffer size needed to store the nil value. The return value is always 1. The function was added to provide integrity of the library.
Equivalent to mp_sizeof_binl(len) + len.
Calculate exact buffer size needed to store a binstring header of length num. Maximum return value is 5. For performance reasons you can preallocate buffer for maximum size without calling the function.
Equivalent to mp_sizeof_strl(len) + len.
Calculate exact buffer size needed to store a string header of length num. Maximum return value is 5. For performance reasons you can preallocate buffer for maximum size without calling the function.
Calculate exact buffer size needed to store a double num. The return value is either 5 or 9. The function was added to provide integrity of the library. For performance reasons you can preallocate buffer for maximum size without calling the function.
Calculate exact buffer size needed to store a float num. The return value is always 5. The function was added to provide integrity of the library.
Calculate exact buffer size needed to store an integer num. Maximum return value is 9. For performance reasons you can preallocate buffer for maximum size without calling the function.
Calculate exact buffer size needed to store an integer num. Maximum return value is 9. For performance reasons you can preallocate buffer for maximum size without calling the function. Example usage:
Calculate exact buffer size needed to store a map header of size elements. Maximum return value is 5. For performance reasons you can preallocate buffer for maximum size without calling the function.
- Parameters
-
size | - a number of elements |
- Returns
- buffer size in bytes (max is 5)
3 my_buffer_ensure(mp_sizeof_uint(x), &end);
4 // my_buffer_ensure(9, &end);
5 mp_encode_uint(buffer, x);
- Parameters
-
- Returns
- buffer size in bytes (max is 9)
- Parameters
-
- Returns
- buffer size in bytes (max is 9)
- Precondition
- num < 0
- Parameters
-
- Returns
- buffer size in bytes (always 5)
- Parameters
-
- Returns
- buffer size in bytes (5 or 9)
- Parameters
-
- Returns
- size in chars (max is 5)
- Parameters
-
- Returns
- size in chars (max is 5 + len)
-
buffer size in bytes (always 1)