File crc.hpp
File List > include > nebula_common > util > crc.hpp
Go to the documentation of this file
// Copyright 2025 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <boost/crc.hpp>
#include <cstdint>
namespace nebula::drivers
{
using crc16_ccit_false_t = boost::crc_ccitt_false_t;
using crc8h2f_t = boost::crc_optimal<8, 0x2F, 0xFF, 0xFF, false, false>;
using crc32_mpeg2_t = boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0x0, false, false>;
template <typename crc_type, typename T, typename U>
typename crc_type::value_type crc(const T * begin, const U * end)
{
const auto * begin_ptr = static_cast<const void *>(begin);
const auto * end_ptr = static_cast<const void *>(end);
crc_type crc_calculator;
crc_calculator.process_block(begin_ptr, end_ptr);
return crc_calculator.checksum();
}
} // namespace nebula::drivers