package
0.9.2
Repository: https://github.com/rokath/tcobs.git
Documentation: pkg.go.dev

# README

TCOBSv1

Table of Contents

1. TCOBSv1 Specification

(back to top)

2. TCOBSv1 Framing Encoder and Decoder

2.1. TCOBSv1 Encoding

  • tcobs.h and tcobsEncode.c contain the encoder as C-code.
  • The decoding in Go is possible with tcobsCDecode.go using tcobsDecode.c with CGO.
  • The decoding in Go is possible also with tcobsDecode.go and recommended.
  • The Go idiomatic usage is to use a NewEncoder(w io.Writer, size int) (p *encoder) and its Reader interface (see read.go)

2.2. TCOBSv1 Decoding

  • tcobsDecode.go contains the decoder as Go-code.
  • tcobs.h and tcobsDecode.c contain the decoder as C-code.
  • The encoding in Go is possible with tcobsCEncode.go using tcobsEncode.c with CGO.
  • The Go idiomatic usage is to use a NewDecoder(r io.Reader, size int, multi bool) (p *decoder) and its Writer interface (see write.go)

2.3. TCOBSv1 Testing

  • *_test.go files contain test code. CGO is not supported inside test files but usable through Go functions.
    • Testing: go test ./...: ../docs/ref/Test.PNG
  • The test execution can take several seconds. If your computer is slow you can reduce the loop count in the test functions TestEncodeDecode*.

(back to top)

3. Getting Started

  • Add ./tcobsEncode.c and/or ./tcobsDecode.c to your embedded project and use function TCOBSEncode and/or TCOBSDecode to convert a buffer to/from TCOBS format.
  • After transmitting one (or more) TCOBS package(s) transmit a 0-delimiter byte.
  • Decoding is implemented also in Go.
    • Encoder and Decoder in other languages are easy to implement using the TCOBS specification and the given C- and Go-code.
  • Contributions are appreciated.

3.1. Prerequisites

  • Just a C compiler and, for testing, a Go installation.

3.2. Installation

  • To use TCOBSv1 with Go execute go get github.com/rokath/tcobs/TCOBSv1

3.3. Usage in Go

  • For example usage check the tests.

3.3.1. Decoding

  • The function tcobs.CDecode is usable standalone.
  • Also it is possible to create a Decoder instance and use the Read method.
  • The function tcobs.Decode is usable standalone.

3.3.2. Encoding

  • The function tcobs.CEncode is usable standalone.
  • Also it is possible to create an Encoder instance and use the Write method.

(back to top)

# Functions

Decode decodes a TCOBS frame `in` (without 0-delimiter) to `d` and returns as `n` the valid data length from the end in `d`.
NewDecoder creates a decoder instance and returns its address.
NewEncoder creates an encoder instance and returns its address.

# Constants

2-FF sigil byte.
3-FF sigil byte.
4-FF sigil byte.
noop sigil byte.
2-repeat sigil byte.
3-repeat sigil byte.
4-repeat sigil byte.
reserved sigil byte.
1-zero sigil byte.
2-zero sigil byte.
3-zero sigil byte.