Skip to content

Consistent Overhead Byte Stuffing (COBS) encoding/decoding package for Swift

License

Notifications You must be signed in to change notification settings

armadsen/GlassGem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GlassGem


GlassGem is a Swift package that implements the Consistent Overhead Byte Stuffing (COBS) algorithm for encoding arbitrary data with single byte packet delimiters.

It consists of an extension on Data with exactly two methods: encodedUsingCOBS() and decodedFromCOBS().

Usage

Encoding:

let someData = ...
let cobsEncodedData = someData.encodedUsingCOBS()
// Do something with cobsEncodedData, e.g. sending across a communications link

Decoding:

let someCOBSEncodeData = ... // e.g. from a communications link
let someData = someData.decodedFromCOBS()
// Use someData like normal

The package includes a suite of unit tests.

Installation

To use the GlassGem library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/armadsen/GlassGem", from: "1.0.0"),

Include "GlassGem" as a dependency for your executable target:

.target(name: "<target>", dependencies: [
    .product(name: "GlassGem", package: "GlassGem"),
]),

Finally, add import GlassGem to your source code.

To Do

GlassGem is already completely usable for the most common scenarios. However, there are a few things I'd like to implement in the future. Pull requests for these are completely welcome. Please include tests for anything you add.

  • Support for using GlassGem from Objective-C
  • Support for arbitrary delimiter bytes, not just 0x00
  • Performance improvements (while still emphasizing readability)
  • Make documentation work with DocC

About

Consistent Overhead Byte Stuffing (COBS) encoding/decoding package for Swift

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages