1/********************************************************************
2 * Copyright (c) 2013 - 2014, Pivotal Inc.
3 * All rights reserved.
4 *
5 * Author: Zhanwei Wang
6 ********************************************************************/
7/********************************************************************
8 * 2014 -
9 * open source under Apache License Version 2.0
10 ********************************************************************/
11/**
12 * Licensed to the Apache Software Foundation (ASF) under one
13 * or more contributor license agreements. See the NOTICE file
14 * distributed with this work for additional information
15 * regarding copyright ownership. The ASF licenses this file
16 * to you under the Apache License, Version 2.0 (the
17 * "License"); you may not use this file except in compliance
18 * with the License. You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28#ifndef _HDFS_LIBHDFS3_COMMON_SWCRC32C_H_
29#define _HDFS_LIBHDFS3_COMMON_SWCRC32C_H_
30
31#include "platform.h"
32
33#include "Checksum.h"
34
35#ifdef NEED_BOOST
36
37#include <boost/crc.hpp>
38
39namespace Hdfs {
40namespace Internal {
41
42typedef boost::crc_optimal<32, 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc_32c_type;
43
44class SWCrc32c: public Checksum {
45public:
46 SWCrc32c() {
47 }
48
49 uint32_t getValue() {
50 return crc.checksum();
51 }
52
53 void reset() {
54 crc.reset();
55 }
56
57 void update(const void * b, int len) {
58 crc.process_bytes(b, len);
59 }
60
61 ~SWCrc32c() {
62 }
63
64private:
65 crc_32c_type crc;
66};
67
68}
69}
70
71#else
72namespace Hdfs {
73namespace Internal {
74
75class SWCrc32c: public Checksum {
76public:
77 SWCrc32c() :
78 crc(0xFFFFFFFF) {
79 }
80
81 uint32_t getValue() {
82 return ~crc;
83 }
84
85 void reset() {
86 crc = 0xFFFFFFFF;
87 }
88
89 void update(const void * b, int len);
90
91 ~SWCrc32c() {
92 }
93
94private:
95 uint32_t crc;
96};
97
98}
99}
100#endif
101
102#endif /* _HDFS_LIBHDFS3_COMMON_SWCRC32C_H_ */
103