# README
TCOBSv1
Table of Contents
1. TCOBSv1 Specification
2. TCOBSv1 Framing Encoder and Decoder
2.1. TCOBSv1 Encoding
-
tcobs.h
andtcobsEncode.c
contain the encoder as C-code. - The decoding in Go is possible with
tcobsCDecode.go
usingtcobsDecode.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 (seeread.go
)
2.2. TCOBSv1 Decoding
-
tcobsDecode.go
contains the decoder as Go-code. -
tcobs.h
andtcobsDecode.c
contain the decoder as C-code. - The encoding in Go is possible with
tcobsCEncode.go
usingtcobsEncode.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 (seewrite.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 ./...
:
- Testing:
- The test execution can take several seconds. If your computer is slow you can reduce the loop count in the test functions
TestEncodeDecode*
.
3. Getting Started
- Add ./tcobsEncode.c and/or ./tcobsDecode.c to your embedded project and use function
TCOBSEncode
and/orTCOBSDecode
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.
# 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.