A CBOR library for Dart developers.
This package provides an encoding/decoding package for the Concise Binary Object Representation as documented in RFC7049.
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.
The Cbor package provides an RFC7049 compliant solution for both the encoding and decoding of CBOR data.
The test suite supports the encoding and decoding examples in Appendix A of RFC7049 amongst others. Specifically :-
The implementation of maps restricts map keys to be of either string or integer type, note however that at the moment decoding to JSON will fail if map keys are not strings.
Please examine the files in the examples directory for usage examples and the API docs for greater detail.
In general the package guarantees to decode what it encodes and should decode all well formed CBOR data. Decoded output takes the form of standard Dart types, i.e. floats become doubles, text become String, arrays become Lists etc. This allows a simple interface for encoding from the Dart world and a simple interface to Dart world from the decoder.
Currently the package supports a payload based decoding, i.e. a complete CBOR entity needs to be submitted to the decoder. Streamed decoding may be supported in future versions. Also error handling is somewhat basic, very badly formed CBOR data may trigger exceptions in the decoding process, if you need to protect against this please enclose all decoding operations in try/catch blocks. If you use this package at both ends of your CBOR interchange nodes you will not need to do this.
Issue 4, update to Dart 2
Updates for pub. Remove json_mapper
Strong mode updates for pub.
// Copyright (c) 2017, steve. All rights reserved. Use of this source code // is governed by a BSD-style license that can be found in the LICENSE file. /// Example file created for pub compatibility only, please refer to the other /// example files in this directory.
Add this to your package's pubspec.yaml file:
dependencies: cbor: ^2.0.2
You can install packages from the command line:
$ pub get
$ flutter pub get
Alternatively, your editor might support
pub get or
flutter pub get.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter, web, other
No platform restriction found in primary library
lib/src/cbor_item_stack.dart. (-25 points)
lib/src/cbor_item_stack.dart failed with 1 error:
line 11 col 35: 'LinkedListEntry' doesn't extend 'LinkedListEntry
lib/src/cbor_decoder.dart. (-5.36 points)
lib/src/cbor_decoder.dart reported 11 hints, including:
line 278 col 11: DO use curly braces for all flow control structures.
line 305 col 11: DO use curly braces for all flow control structures.
line 334 col 11: DO use curly braces for all flow control structures.
line 356 col 11: DO use curly braces for all flow control structures.
line 364 col 11: DO use curly braces for all flow control structures.
lib/src/cbor_encoder.dart. (-1.99 points)
lib/src/cbor_encoder.dart reported 4 hints:
line 86 col 33: Don't explicitly initialize variables to null.
line 107 col 33: Don't explicitly initialize variables to null.
line 389 col 33: Don't explicitly initialize variables to null.
line 477 col 33: Don't explicitly initialize variables to null.
lib/src/cbor_listener_stack.dart. (-1.49 points)
lib/src/cbor_listener_stack.dart reported 3 hints:
line 370 col 13: Use isEmpty instead of length
line 480 col 9: Use isNotEmpty instead of length
line 490 col 9: Use isNotEmpty instead of length
lib/src/cbor_dart_item.dart. (-0.50 points)
lib/src/cbor_dart_item.dart reported 1 hint:
line 50 col 11: Don't explicitly initialize variables to null.