aboutsummaryrefslogtreecommitdiff
path: root/third_party/crc32c/src/include/crc32c/crc32c.h
blob: e8a78170a91cb69b5b00ae97fa398a373188c716 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Copyright 2017 The CRC32C Authors. All rights reserved.
   Use of this source code is governed by a BSD-style license that can be
   found in the LICENSE file. See the AUTHORS file for names of contributors. */

#ifndef CRC32C_CRC32C_H_
#define CRC32C_CRC32C_H_

/* The API exported by the CRC32C project. */

#if defined(__cplusplus)

#include <cstddef>
#include <cstdint>
#include <string>

#else  /* !defined(__cplusplus) */

#include <stddef.h>
#include <stdint.h>

#endif  /* !defined(__cplusplus) */


/* The C API. */

#if defined(__cplusplus)
extern "C" {
#endif  /* defined(__cplusplus) */

/* Extends "crc" with the CRC32C of "count" bytes in the buffer pointed by
   "data" */
uint32_t crc32c_extend(uint32_t crc, const uint8_t* data, size_t count);

/* Computes the CRC32C of "count" bytes in the buffer pointed by "data". */
uint32_t crc32c_value(const uint8_t* data, size_t count);

#ifdef __cplusplus
}  /* end extern "C" */
#endif  /* defined(__cplusplus) */


/* The C++ API. */

#if defined(__cplusplus)

namespace crc32c {

// Extends "crc" with the CRC32C of "count" bytes in the buffer pointed by
// "data".
uint32_t Extend(uint32_t crc, const uint8_t* data, size_t count);

// Computes the CRC32C of "count" bytes in the buffer pointed by "data".
inline uint32_t Crc32c(const uint8_t* data, size_t count) {
  return Extend(0, data, count);
}

// Computes the CRC32C of "count" bytes in the buffer pointed by "data".
inline uint32_t Crc32c(const char* data, size_t count) {
  return Extend(0, reinterpret_cast<const uint8_t*>(data), count);
}

// Computes the CRC32C of the string's content.
inline uint32_t Crc32c(const std::string& string) {
  return Crc32c(reinterpret_cast<const uint8_t*>(string.data()),
                string.size());
}

}  // namespace crc32c

#if __cplusplus > 201402L
#if __has_include(<string_view>)
#include <string_view>

namespace crc32c {

// Computes the CRC32C of the bytes in the string_view.
inline uint32_t Crc32c(const std::string_view& string_view) {
  return Crc32c(reinterpret_cast<const uint8_t*>(string_view.data()),
                string_view.size());
}

}  // namespace crc32c

#endif  // __has_include(<string_view>)
#endif  // __cplusplus > 201402L

#endif  /* defined(__cplusplus) */

#endif  // CRC32C_CRC32C_H_