Skip to content

Commit 18fa793

Browse files
committed
TCOBSv1Encode added
1 parent d14262a commit 18fa793

File tree

3 files changed

+499
-1
lines changed

3 files changed

+499
-1
lines changed

cmd/TCOBSv1Encode/main.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"log"
7+
"os"
8+
9+
tcobs "github.com/rokath/tcobs/Cv2"
10+
"github.com/spf13/afero"
11+
)
12+
13+
var (
14+
// do not initialize, goreleaser will handle that
15+
version string
16+
17+
// do not initialize, goreleaser will handle that
18+
commit string
19+
20+
// do not initialize, goreleaser will handle that
21+
date string
22+
)
23+
24+
// main is the entry point.
25+
func main() {
26+
fSys := &afero.Afero{Fs: afero.NewOsFs()} // os.DirFS("")
27+
doit(os.Stdout, fSys)
28+
}
29+
30+
func doit(w io.Writer, fSys *afero.Afero) {
31+
32+
if len(os.Args) != 1 {
33+
fmt.Fprintln(w, version, commit, date)
34+
fmt.Fprintln(w, "Feed with a space separated byte sequence to convert it in a TCOBSv1 sequence.")
35+
fmt.Fprintln(w, "Example: `echo 0xaa 123 0b1010 44 44 44 | TCOBSv1Encode` will return `170 123 10 44 132`")
36+
return
37+
}
38+
39+
var i []byte
40+
o := make([]byte, 16*1024)
41+
var pos int
42+
for {
43+
var n byte
44+
_, err := fmt.Scan(&n)
45+
if err == io.EOF {
46+
if len(i)+31/len(i) > len(o) {
47+
log.Fatal("len of internal buffer too small")
48+
}
49+
count := tcobs.CEncode(o, i)
50+
o = o[:count]
51+
for _, b := range o {
52+
fmt.Fprintf(w, "%d ", b)
53+
}
54+
return
55+
}
56+
if err != nil {
57+
log.Fatal(err, " at position ", pos)
58+
}
59+
i = append(i, n)
60+
pos++
61+
}
62+
}

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ module github.com/rokath/tcobs
33
go 1.19
44

55
require (
6+
github.com/spf13/afero v1.9.5
67
github.com/stretchr/testify v1.8.1
78
github.com/tj/assert v0.0.3
89
)
910

1011
require (
1112
github.com/davecgh/go-spew v1.1.1 // indirect
1213
github.com/pmezard/go-difflib v1.0.0 // indirect
14+
golang.org/x/text v0.3.7 // indirect
1315
gopkg.in/yaml.v3 v3.0.1 // indirect
1416
)

0 commit comments

Comments
 (0)