Skip to content

Commit

Permalink
TCOBSv1Encode added
Browse files Browse the repository at this point in the history
  • Loading branch information
th-sabik committed Sep 10, 2023
1 parent d14262a commit 18fa793
Show file tree
Hide file tree
Showing 3 changed files with 499 additions and 1 deletion.
62 changes: 62 additions & 0 deletions cmd/TCOBSv1Encode/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"fmt"
"io"
"log"
"os"

tcobs "github.com/rokath/tcobs/Cv2"
"github.com/spf13/afero"
)

var (
// do not initialize, goreleaser will handle that
version string

// do not initialize, goreleaser will handle that
commit string

// do not initialize, goreleaser will handle that
date string
)

// main is the entry point.
func main() {
fSys := &afero.Afero{Fs: afero.NewOsFs()} // os.DirFS("")
doit(os.Stdout, fSys)
}

func doit(w io.Writer, fSys *afero.Afero) {

if len(os.Args) != 1 {
fmt.Fprintln(w, version, commit, date)
fmt.Fprintln(w, "Feed with a space separated byte sequence to convert it in a TCOBSv1 sequence.")
fmt.Fprintln(w, "Example: `echo 0xaa 123 0b1010 44 44 44 | TCOBSv1Encode` will return `170 123 10 44 132`")
return
}

var i []byte
o := make([]byte, 16*1024)
var pos int
for {
var n byte
_, err := fmt.Scan(&n)
if err == io.EOF {
if len(i)+31/len(i) > len(o) {
log.Fatal("len of internal buffer too small")
}
count := tcobs.CEncode(o, i)
o = o[:count]
for _, b := range o {
fmt.Fprintf(w, "%d ", b)
}
return
}
if err != nil {
log.Fatal(err, " at position ", pos)
}
i = append(i, n)
pos++
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ module github.com/rokath/tcobs
go 1.19

require (
github.com/spf13/afero v1.9.5
github.com/stretchr/testify v1.8.1
github.com/tj/assert v0.0.3
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 18fa793

Please sign in to comment.