搜尋套件、儲存庫與 APP 分類

套件詳情v3.0.0

crclib

一組循環冗餘檢查 (CRC) 常用程式,作為 Dart 轉換器。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
16.2萬
喜歡數
16
Pub 分數
140

安裝套件

flutter pub add crclib

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

crclib 是一個 Dart 套件,提供一組循環冗餘檢查(CRC)例程作為轉換器,設計用於高效資料完整性驗證。它支援多種 CRC 算法,並能順暢整合至跨 Android、iOS、Web、macOS、Windows 及 Linux 的 Flutter 應用程式。此套件非常適合用於檔案傳輸、網路通訊及嵌入式系統中的資料一致性驗證。以極小的開銷與直覺的使用方式,crclib 讓開發者能輕鬆實作強大的校驗和驗證。

適用情境

  • 檔案傳輸中的資料完整性檢查
  • 網路資料封包驗證
  • 嵌入式系統數據驗證
  • 固件更新的校驗和生成
  • 即時資料流完整性
  • 跨平台CRC計算

主要特色

  • 支援多種CRC演算法
  • 輕量且快速的轉換器
  • 跨平台相容性
  • 簡單的 API 結合
  • 內建測試案例
  • 可擴展的演算法設計

適合對象

  • 需要可靠CRC驗證的開發者
  • 需要資料一致性檢查的應用程式
  • 具有完整性需求的跨平台專案
  • 韌體與嵌入式軟體開發
  • 網路協定實作

使用建議

  • 確保為用例選擇正確的CRC算法
  • 在處理前驗證輸入資料格式
  • 不適合用於加密雜湊
  • 對大型資料流的效能影響
  • 僅限CRC特定用途
  • 需要小心處理位元組陣列

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Dart crclib

This is not an official Google product.

Generic CRC calculations as Dart converters and some common algorithms.

To calculate the CRC value of any message

The easiest way to use this library is to call convert on the instance of the desired CRC routine.

  Crc32Xz().convert(utf8.encode('123456789')) == 0xCBF43926

Another supported use case is as stream transformers.

  File(...).openRead().transform(Crc32Xz()).single.then(...)

Instead of using predefined classes, it is also possible to construct a customized CRC function with ParametricCrc class. For a list of known CRC routines, check out https://reveng.sourceforge.io/crc-catalogue/all.htm.

TODO:

  1. inputReflected and outputReflected can be different, see CRC-12/UMTS.
  2. Bit-level checksums (including non-multiple-of-8 checksums).

To flip bits to obtain desired CRC values

With CrcFlipper, one can call flipWithData or flipWithValue depending on whether they have access to the message, or only its calculated CRC value. The snippet below is taken from test/flipper_test.dart.

      var inputMessage =
          'flipping lowercases to uppercases like mama pig making hot pancakes '
          'for daddy pig in peppa pig cartoon';
      // Mark the lower/upper-case bit in each character.
      // 0x61 = 'a' = 0110 0001
      //                | <-- 5th bit, zero-indexed
      // 0x41 = 'A' = 0100 0001
      var positions = inputMessage.codeUnits
          .asMap()
          .entries
          .where((e) => e.value >= 0x61 && e.value < 0x61 + 26)
          .map((e) => e.key * 8 + 5)
          .toSet();
      var flipper = CrcFlipper(Crc64());
      var solution = flipper.flipWithData(inputMessage.codeUnits, positions,
          CrcValue(BigInt.parse('DEADBEEFCAFEBABE', radix: 16)))!;
      var tmp = List.of(inputMessage.codeUnits, growable: false);
      solution.forEach((bitPosition) {
        var mask = 1 << (bitPosition % 8);
        tmp[bitPosition ~/ 8] ^= mask;
      });
      var outputMessage = String.fromCharCodes(tmp);
      expect(
          outputMessage,
          'flIPpiNG LOWErcAsEs To uPpERcaseS LIkE mAmA Pig mAKInG hOT paNcAKEs '
          'For DAdDY pig in peppa pig cartoon');

The detailed algorithm is documented in flipping_algorithm.md.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案