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

套件詳情v6.5.2

cbor

Dart 的 CBOR 庫。符合 RFC8949 標準的 CBOR 編碼/解碼實作。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
32.2萬
喜歡數
41
Pub 分數
160

安裝套件

flutter pub add cbor

套件介紹

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

一個用於編碼和解碼CBOR(緊湊二進位物件表示)資料的Dart程式庫,符合RFC8949標準。它能將結構化資料高效序列化為緊湊的二進位格式,非常適合對頻寬與效能有要求的物聯網、行動與Web應用。該套件支援所有標準CBOR類型,並可順暢整合至Dart生態系統中。

適用情境

  • 物聯網裝置中的高效資料序列化
  • 移動應用中的緊湊有效載荷傳輸
  • 與使用 CBOR 的系統的互操作性
  • Web API 數據交換
  • 在輕量級格式中嵌入二進制數據

主要特色

  • 符合 RFC8949
  • 支援所有CBOR資料類型
  • 輕量級二進制編碼
  • 跨平台相容性
  • 用於編碼/解碼的簡單 API
  • 適用於所有主要平台

適合對象

  • 需要緊湊資料格式的開發人員
  • 需要高效率序列化的應用程式
  • 透過CBOR通訊的系統
  • 帶寬有限的行動和網頁應用

使用建議

  • 僅限 CBOR 格式
  • 不支援內建架構驗證
  • 需要理解 CBOR 語義
  • 不適合人類可讀的資料

原始 README

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

cbor

Build Status Pub Version

Documentation

This package provides an encoding/decoding package for the Concise Binary Object Representation as documented in RFC8949.

CBOR is increasingly used as a line protocol in the IOT world where the overhead of transmitting JSON on constrained devices can be large in packet size and processing overheads.

Features

  • Streamlined encoding and decoding of CBOR, including indefinite length and streamed decoding.
  • Set of types that semantically handles types, nesting, and tags.
  • Automatic conversion for the smallest size needed for integers.
  • Automatic conversion for the smallest precision needed for floating point numbers.
  • Any value can be the key for a map.
  • Optional simple API for encoding and decoding directly to Dart objects.
  • Pretty-printing and conversion to JSON.
  • Rational numbering encoding is supported on tag 30.

Usage

Two APIs are provided, cbor.dart and simple.dart.

cbor.dart

Encodes from CborValue and decodes to CborValue.

The CborValue contains the tags for this item, and its subtypes are used to identify the type and tags for the item. This allows one to handle information encoded in a more lossless way.

Inheritance tree for CborValue looks something like this:

CborValue
├── CborInt
│   ├── CborSmallInt
│   └── CborDateTimeInt
├── CborBytes
│   └── CborBigInt
├── CborString
│   ├── CborDateTimeString
│   ├── CborBase64
│   ├── CborBase64Url
│   ├── CborMime
│   └── CborRegex
├── CborFloat
│   └── CborDateTimeFloat
├── CborSimpleValue
│   ├── CborNull
│   ├── CborBool
│   └── CborUndefined
├── CborMap
└── CborList
    ├── CborDecimalFraction
    ├── CborRationalNumber
    └── CborBigFloat
Example
import 'package:cbor/cbor.dart';

test('{1:2,3:4}', () {
   final encoded = cbor.encode(CborMap({
      CborSmallInt(1): CborSmallInt(2),
      CborSmallInt(3): CborSmallInt(4),
   }));
   expect(encoded, [0xa2, 0x01, 0x02, 0x03, 0x04]);
});

Check out the example folder for more examples.

simple.dart

Less powerful, but may be the best option for simple applications that do not need any of the fancy features of the cbor API above.

The encoder in simple API will operate similarly to constructing a CborValue from the input and the encoding it.

Decoder will translate the input to a common Dart object, ignoring any extra tags after the type is decided.

Example
import 'package:cbor/simple.dart';

test('{1:2,3:4}', () {
   final encoded = cbor.encode({
      1: 2,
      3: 4,
   });
   expect(encoded, [0xa2, 0x01, 0x02, 0x03, 0x04]);
});
Additional RFC's implemented

The following CBOR RFC's have also been implemented in the package :-

  • RFC8746 - Concise Binary Object Representation (CBOR) Tags for Typed Arrays.

所屬分類

依賴

依賴清單 6 項

原始碼儲存庫

使用此套件的專案