1 /* Copyright 2013 Google Inc. All Rights Reserved. 2 3 Distributed under MIT license. 4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT 5 */ 6 7 /** 8 * @file 9 * Common types used in decoder and encoder API. 10 */ 11 12 #ifndef BROTLI_COMMON_TYPES_H_ 13 #define BROTLI_COMMON_TYPES_H_ 14 15 #include <stddef.h> /* for size_t */ 16 17 #if defined(_MSC_VER) && (_MSC_VER < 1600) 18 typedef __int8 int8_t; 19 typedef unsigned __int8 uint8_t; 20 typedef __int16 int16_t; 21 typedef unsigned __int16 uint16_t; 22 typedef __int32 int32_t; 23 typedef unsigned __int32 uint32_t; 24 typedef unsigned __int64 uint64_t; 25 typedef __int64 int64_t; 26 #else 27 #include <stdint.h> 28 #endif /* defined(_MSC_VER) && (_MSC_VER < 1600) */ 29 30 /** 31 * A portable @c bool replacement. 32 * 33 * ::BROTLI_BOOL is a "documentation" type: actually it is @c int, but in API it 34 * denotes a type, whose only values are ::BROTLI_TRUE and ::BROTLI_FALSE. 35 * 36 * ::BROTLI_BOOL values passed to Brotli should either be ::BROTLI_TRUE or 37 * ::BROTLI_FALSE, or be a result of ::TO_BROTLI_BOOL macros. 38 * 39 * ::BROTLI_BOOL values returned by Brotli should not be tested for equality 40 * with @c true, @c false, ::BROTLI_TRUE, ::BROTLI_FALSE, but rather should be 41 * evaluated, for example: @code{.cpp} 42 * if (SomeBrotliFunction(encoder, BROTLI_TRUE) && 43 * !OtherBrotliFunction(decoder, BROTLI_FALSE)) { 44 * bool x = !!YetAnotherBrotliFunction(encoder, TO_BROLTI_BOOL(2 * 2 == 4)); 45 * DoSomething(x); 46 * } 47 * @endcode 48 */ 49 #define BROTLI_BOOL int 50 /** Portable @c true replacement. */ 51 #define BROTLI_TRUE 1 52 /** Portable @c false replacement. */ 53 #define BROTLI_FALSE 0 54 /** @c bool to ::BROTLI_BOOL conversion macros. */ 55 #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE) 56 57 #define BROTLI_MAKE_UINT64_T(high, low) ((((uint64_t)(high)) << 32) | low) 58 59 #define BROTLI_UINT32_MAX (~((uint32_t)0)) 60 #define BROTLI_SIZE_MAX (~((size_t)0)) 61 62 /** 63 * Allocating function pointer type. 64 * 65 * @param opaque custom memory manager handle provided by client 66 * @param size requested memory region size; can not be @c 0 67 * @returns @c 0 in the case of failure 68 * @returns a valid pointer to a memory region of at least @p size bytes 69 * long otherwise 70 */ 71 typedef void* (*brotli_alloc_func)(void* opaque, size_t size); 72 73 /** 74 * Deallocating function pointer type. 75 * 76 * This function @b SHOULD do nothing if @p address is @c 0. 77 * 78 * @param opaque custom memory manager handle provided by client 79 * @param address memory region pointer returned by ::brotli_alloc_func, or @c 0 80 */ 81 typedef void (*brotli_free_func)(void* opaque, void* address); 82 83 #endif /* BROTLI_COMMON_TYPES_H_ */ 84