cbor
Dart용 CBOR 라이브러리입니다. RFC8949 호환 인코딩/디코딩 CBOR 구현입니다.
Dart용 CBOR 구현
^1.17.2^1.3.2^0.2.0^3.1.2^1.9.1^1.4.0^1.28.0^6.0.0^2.10.5^3.5.5^4.4.7^1.0.3아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
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.
Two APIs are provided, cbor.dart and simple.dart.
cbor.dartEncodes 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
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.dartLess 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.
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]);
});
The following CBOR RFC's have also been implemented in the package :-