搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目