| 28 | static CompressHandler s_handler_map[MAX_HANDLER_SIZE] = { { NULL, NULL, NULL } }; |
| 29 | |
| 30 | int RegisterCompressHandler(CompressType type, |
| 31 | CompressHandler handler) { |
| 32 | if (NULL == handler.Compress || NULL == handler.Decompress) { |
| 33 | LOG(FATAL) << "Invalid parameter: handler function is NULL"; |
| 34 | return -1; |
| 35 | } |
| 36 | int index = type; |
| 37 | if (index < 0 || index >= MAX_HANDLER_SIZE) { |
| 38 | LOG(FATAL) << "CompressType=" << type << " is out of range"; |
| 39 | return -1; |
| 40 | } |
| 41 | if (s_handler_map[index].Compress != NULL) { |
| 42 | LOG(FATAL) << "CompressType=" << type << " was registered"; |
| 43 | return -1; |
| 44 | } |
| 45 | s_handler_map[index] = handler; |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | // Find CompressHandler by type. |
| 50 | // Returns NULL if not found |
no outgoing calls
no test coverage detected