1 /* transforms is a part of ABI, but not API. 2 3 It means that there are some functions that are supposed to be in "common" 4 library, but header itself is not placed into include/brotli. This way, 5 aforementioned functions will be available only to brotli internals. 6 */ 7 8 #ifndef BROTLI_COMMON_TRANSFORM_H_ 9 #define BROTLI_COMMON_TRANSFORM_H_ 10 11 #include <brotli/port.h> 12 #include <brotli/types.h> 13 14 #if defined(__cplusplus) || defined(c_plusplus) 15 extern "C" { 16 #endif 17 18 enum BrotliWordTransformType { 19 BROTLI_TRANSFORM_IDENTITY = 0, 20 BROTLI_TRANSFORM_OMIT_LAST_1 = 1, 21 BROTLI_TRANSFORM_OMIT_LAST_2 = 2, 22 BROTLI_TRANSFORM_OMIT_LAST_3 = 3, 23 BROTLI_TRANSFORM_OMIT_LAST_4 = 4, 24 BROTLI_TRANSFORM_OMIT_LAST_5 = 5, 25 BROTLI_TRANSFORM_OMIT_LAST_6 = 6, 26 BROTLI_TRANSFORM_OMIT_LAST_7 = 7, 27 BROTLI_TRANSFORM_OMIT_LAST_8 = 8, 28 BROTLI_TRANSFORM_OMIT_LAST_9 = 9, 29 BROTLI_TRANSFORM_UPPERCASE_FIRST = 10, 30 BROTLI_TRANSFORM_UPPERCASE_ALL = 11, 31 BROTLI_TRANSFORM_OMIT_FIRST_1 = 12, 32 BROTLI_TRANSFORM_OMIT_FIRST_2 = 13, 33 BROTLI_TRANSFORM_OMIT_FIRST_3 = 14, 34 BROTLI_TRANSFORM_OMIT_FIRST_4 = 15, 35 BROTLI_TRANSFORM_OMIT_FIRST_5 = 16, 36 BROTLI_TRANSFORM_OMIT_FIRST_6 = 17, 37 BROTLI_TRANSFORM_OMIT_FIRST_7 = 18, 38 BROTLI_TRANSFORM_OMIT_FIRST_8 = 19, 39 BROTLI_TRANSFORM_OMIT_FIRST_9 = 20, 40 BROTLI_TRANSFORM_SHIFT_FIRST = 21, 41 BROTLI_TRANSFORM_SHIFT_ALL = 22, 42 BROTLI_NUM_TRANSFORM_TYPES /* Counts transforms, not a transform itself. */ 43 }; 44 45 #define BROTLI_TRANSFORMS_MAX_CUT_OFF BROTLI_TRANSFORM_OMIT_LAST_9 46 47 typedef struct BrotliTransforms { 48 uint16_t prefix_suffix_size; 49 /* Last character must be null, so prefix_suffix_size must be at least 1. */ 50 const uint8_t* prefix_suffix; 51 const uint16_t* prefix_suffix_map; 52 uint32_t num_transforms; 53 /* Each entry is a [prefix_id, transform, suffix_id] triplet. */ 54 const uint8_t* transforms; 55 /* Shift for BROTLI_TRANSFORM_SHIFT_FIRST and BROTLI_TRANSFORM_SHIFT_ALL, 56 must be NULL if and only if no such transforms are present. */ 57 const uint8_t* params; 58 /* Indices of transforms like ["", BROTLI_TRANSFORM_OMIT_LAST_#, ""]. 59 0-th element corresponds to ["", BROTLI_TRANSFORM_IDENTITY, ""]. 60 -1, if cut-off transform does not exist. */ 61 int16_t cutOffTransforms[BROTLI_TRANSFORMS_MAX_CUT_OFF + 1]; 62 } BrotliTransforms; 63 64 /* T is BrotliTransforms*; result is uint8_t. */ 65 #define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0]) 66 #define BROTLI_TRANSFORM_TYPE(T, I) ((T)->transforms[((I) * 3) + 1]) 67 #define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2]) 68 69 /* T is BrotliTransforms*; result is const uint8_t*. */ 70 #define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \ 71 (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]]) 72 #define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \ 73 (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]]) 74 75 BROTLI_COMMON_API const BrotliTransforms* BrotliGetTransforms(void); 76 77 BROTLI_COMMON_API int BrotliTransformDictionaryWord( 78 uint8_t* dst, const uint8_t* word, int len, 79 const BrotliTransforms* transforms, int transform_idx); 80 81 #if defined(__cplusplus) || defined(c_plusplus) 82 } /* extern "C" */ 83 #endif 84 85 #endif /* BROTLI_COMMON_TRANSFORM_H_ */ 86