@@ -15,28 +15,32 @@ limitations under the License.
15
15
*/
16
16
#pragma once
17
17
#include < cstdint>
18
- #include < string>
18
+ #include < photon/common/string_view.h>
19
+
20
+ uint32_t crc32c_sw (const uint8_t *buffer, size_t nbytes, uint32_t crc);
21
+
22
+ uint32_t crc32c_hw (const uint8_t *data, size_t nbytes, uint32_t crc);
19
23
20
24
/* *
21
25
* @brief We recommand using of crc32c() and crc32c_extend(), which can exploit hardware
22
26
* acceleartion automatically. In case of using crc32c_hw() directly, please make sure invoking
23
27
* is_crc32c_hw_available() to detect whether hardware acceleartion is available at first;
24
28
*
25
29
*/
26
- uint32_t crc32c (const void *data, size_t nbytes);
27
-
28
- uint32_t crc32c_extend (const void *data, size_t nbytes, uint32_t crc);
30
+ inline uint32_t crc32c_extend (const void *data, size_t nbytes, uint32_t crc) {
31
+ extern uint32_t (*crc32c_auto)(const uint8_t *data, size_t nbytes, uint32_t crc);
32
+ return crc32c_auto ((uint8_t *)data, nbytes, crc);
33
+ }
29
34
30
- inline uint32_t crc32c (const std::string &text ) {
31
- return crc32c_extend (text. data (), text. size () , 0 );
35
+ inline uint32_t crc32c (const void *data, size_t nbytes ) {
36
+ return crc32c_extend (( uint8_t *)data, nbytes , 0 );
32
37
}
33
38
34
- inline uint32_t crc32c_extend (const std::string & text, uint32_t crc) {
39
+ inline uint32_t crc32c_extend (std::string_view text, uint32_t crc = 0 ) {
35
40
return crc32c_extend (text.data (), text.size (), crc);
36
41
}
37
42
38
- uint32_t crc32c_sw (const uint8_t *buffer, size_t nbytes, uint32_t crc);
39
-
40
- uint32_t crc32c_hw (const uint8_t *data, size_t nbytes, uint32_t crc);
41
-
42
- bool is_crc32c_hw_available ();
43
+ inline bool is_crc32c_hw_available () {
44
+ extern uint32_t (*crc32c_auto)(const uint8_t *data, size_t nbytes, uint32_t crc);
45
+ return crc32c_auto == crc32c_hw;
46
+ }
0 commit comments