1 /* 2 +----------------------------------------------------------------------+ 3 | See COPYING file for further copyright information | 4 +----------------------------------------------------------------------+ 5 | Author: Oleg Grenrus <oleg.grenrus@dynamoid.com> | 6 | See CREDITS for contributors | 7 +----------------------------------------------------------------------+ 8 */ 9 10 #ifndef IGBINARY_H 11 #define IGBINARY_H 12 #include <stdint.h> 13 14 /* Forward declarations. */ 15 struct zval; 16 17 /* Constants and constant macros */ 18 /** Binary protocol version of igbinary. */ 19 #define IGBINARY_FORMAT_VERSION 0x00000002 20 21 #define PHP_IGBINARY_VERSION "3.2.6" 22 23 /* Macros */ 24 25 #ifdef PHP_WIN32 26 # if defined(IGBINARY_EXPORTS) || (!defined(COMPILE_DL_IGBINARY)) 27 # define IGBINARY_API __declspec(dllexport) 28 # elif defined(COMPILE_DL_IGBINARY) 29 # define IGBINARY_API __declspec(dllimport) 30 # else 31 # define IGBINARY_API /* nothing special */ 32 # endif 33 #elif defined(__GNUC__) && __GNUC__ >= 4 34 # define IGBINARY_API __attribute__ ((visibility("default"))) 35 #else 36 # define IGBINARY_API /* nothing special */ 37 #endif 38 39 /** Struct that contains pointers to memory allocation and deallocation functions. 40 * @see igbinary_serialize_data 41 */ 42 struct igbinary_memory_manager { 43 void *(*alloc)(size_t size, void *context); 44 void *(*realloc)(void *ptr, size_t new_size, void *context); 45 void (*free)(void *ptr, void *context); 46 void *context; 47 }; 48 49 /** Serialize zval. 50 * Return buffer is allocated by this function with emalloc. 51 * @param[out] ret Return buffer 52 * @param[out] ret_len Size of return buffer 53 * @param[in] z Variable to be serialized 54 * @return 0 on success, 1 elsewhere. 55 */ 56 IGBINARY_API int igbinary_serialize(uint8_t **ret, size_t *ret_len, zval *z); 57 58 /** Serialize zval. 59 * Return buffer is allocated by this function with emalloc. 60 * @param[out] ret Return buffer 61 * @param[out] ret_len Size of return buffer 62 * @param[in] z Variable to be serialized 63 * @param[in] memory_manager Pointer to the structure that contains memory allocation functions. 64 * @return 0 on success, 1 elsewhere. 65 */ 66 IGBINARY_API int igbinary_serialize_ex(uint8_t **ret, size_t *ret_len, zval *z, struct igbinary_memory_manager *memory_manager); 67 68 /** Unserialize to zval. 69 * @param[in] buf Buffer with serialized data. 70 * @param[in] buf_len Buffer length. 71 * @param[out] z Unserialized zval 72 * @return 0 on success, 1 elsewhere. 73 */ 74 IGBINARY_API int igbinary_unserialize(const uint8_t *buf, size_t buf_len, zval *z); 75 76 #endif /* IGBINARY_H */ 77