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