]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/BrotliCustomDecompressLib/brotli/types.h
35c95696423ea78376ababf7e90912c8ecb340c2
[mirror_edk2.git] / MdeModulePkg / Library / BrotliCustomDecompressLib / brotli / types.h
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 typedef UINTN size_t;
17
18 #if defined(_MSC_VER) && (_MSC_VER < 1600)
19 typedef __int8 int8_t;
20 typedef unsigned __int8 uint8_t;
21 typedef __int16 int16_t;
22 typedef unsigned __int16 uint16_t;
23 typedef __int32 int32_t;
24 typedef unsigned __int32 uint32_t;
25 typedef unsigned __int64 uint64_t;
26 typedef __int64 int64_t;
27 #else
28 //#include <stdint.h>
29 typedef INT8 int8_t;
30 typedef INT16 int16_t;
31 typedef INT32 int32_t;
32 typedef INT64 int64_t;
33 typedef UINT8 uint8_t;
34 typedef UINT16 uint16_t;
35 typedef UINT32 uint32_t;
36 typedef UINT64 uint64_t;
37 #endif /* defined(_MSC_VER) && (_MSC_VER < 1600) */
38
39 /**
40 * A portable @c bool replacement.
41 *
42 * ::BROTLI_BOOL is a "documentation" type: actually it is @c int, but in API it
43 * denotes a type, whose only values are ::BROTLI_TRUE and ::BROTLI_FALSE.
44 *
45 * ::BROTLI_BOOL values passed to Brotli should either be ::BROTLI_TRUE or
46 * ::BROTLI_FALSE, or be a result of ::TO_BROTLI_BOOL macros.
47 *
48 * ::BROTLI_BOOL values returned by Brotli should not be tested for equality
49 * with @c true, @c false, ::BROTLI_TRUE, ::BROTLI_FALSE, but rather should be
50 * evaluated, for example: @code{.cpp}
51 * if (SomeBrotliFunction(encoder, BROTLI_TRUE) &&
52 * !OtherBrotliFunction(decoder, BROTLI_FALSE)) {
53 * bool x = !!YetAnotherBrotliFunction(encoder, TO_BROLTI_BOOL(2 * 2 == 4));
54 * DoSomething(x);
55 * }
56 * @endcode
57 */
58 #define BROTLI_BOOL int
59 /** Portable @c true replacement. */
60 #define BROTLI_TRUE 1
61 /** Portable @c false replacement. */
62 #define BROTLI_FALSE 0
63 /** @c bool to ::BROTLI_BOOL conversion macros. */
64 #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
65
66 #define BROTLI_MAKE_UINT64_T(high, low) ((((uint64_t)(high)) << 32) | low)
67
68 #define BROTLI_UINT32_MAX (~((uint32_t)0))
69 #define BROTLI_SIZE_MAX (~((size_t)0))
70
71 /**
72 * Allocating function pointer type.
73 *
74 * @param opaque custom memory manager handle provided by client
75 * @param size requested memory region size; can not be @c 0
76 * @returns @c 0 in the case of failure
77 * @returns a valid pointer to a memory region of at least @p size bytes
78 * long otherwise
79 */
80 typedef void* (*brotli_alloc_func)(void* opaque, size_t size);
81
82 /**
83 * Deallocating function pointer type.
84 *
85 * This function @b SHOULD do nothing if @p address is @c 0.
86 *
87 * @param opaque custom memory manager handle provided by client
88 * @param address memory region pointer returned by ::brotli_alloc_func, or @c 0
89 */
90 typedef void (*brotli_free_func)(void* opaque, void* address);
91
92 #endif /* BROTLI_COMMON_TYPES_H_ */