cobs 0.1.0

  • Readme
  • Changelog
  • Installing
  • 48

Consistent Overhead Byte Stuffing (COBS) implementation in Dart. #

This package is a Dart port of original COBS implementation in C by Craig McQueen and influenced by the Java implementation by TheMarpe (

Intro #

A library is provided, which contains functions for encoding and decoding according to COBS methods.

What Is COBS? #

COBS is a method of encoding a packet of bytes into a form that contains no bytes with value zero (0x00). The input packet of bytes can contain bytes in the full range of 0x00 to 0xFF. The COBS encoded packet is guaranteed to generate packets with bytes only in the range 0x01 to 0xFF. Thus, in a communication protocol, packet boundaries can be reliably delimited with 0x00 bytes.

The COBS encoding does have to increase the packet size to achieve this encoding. However, compared to other byte-stuffing methods, the packet size increase is reasonable and predictable. COBS always adds 1 byte to the message length. Additionally, for longer packets of length n, it may add n/254 (rounded down) additional bytes to the encoded packet size.

For example, compare to the PPP protocol, which uses 0x7E bytes to delimit PPP packets. The PPP protocol uses an "escape" style of byte stuffing, replacing all occurrences of 0x7E bytes in the packet with 0x7D 0x5E. But that byte-stuffing method can potentially double the size of the packet in the worst case. COBS uses a different method for byte-stuffing, which has a much more reasonable worst-case overhead.

For more details about COBS, see the references 1 2.

References #

Consistent Overhead Byte Stuffing
Stuart Cheshire and Mary Baker
IEEE/ACM Transations on Networking, Vol. 7, No. 2, April 1999

PPP Consistent Overhead Byte Stuffing (COBS)
PPP Working Group Internet Draft
James Carlson, IronBridge Networks
Stuart Cheshire and Mary Baker, Stanford University, November 1997

[0.1.0] - 28 April 2019 #

  • Implement Stream decoding
  • Add withZero optional parameter to encodeDstBufMaxLen and encodeCOBS() to append a zero byte to the end of the encoded packet.
  • Add dartdoc comments

[0.0.1] - 28 April 2019 #

  • Initial release of Dart implementation of COBS algorithm.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  cobs: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:cobs/cobs.dart';
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]
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.9+1

Health suggestions

Fix lib/cobs.dart. (-1 points)

Analysis of lib/cobs.dart reported 2 hints:

line 54 col 25: Unnecessary new keyword.

line 140 col 25: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-17.81 points)

The package was last published 61 weeks ago.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and cobs.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
collection ^1.14.11
test any