Skip to content

Commit e72aa53

Browse files
committed
better error handling
1 parent c252150 commit e72aa53

File tree

13 files changed

+94
-12
lines changed

13 files changed

+94
-12
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# TCOBS Changelog
22

3+
## v0.9.2
4+
5+
* not needed project files & foldes removed
6+
* demo binaries added
7+
* Folders Cv1 & Cv2 renamed into v1 & v2
8+
* goreleaser config file added
9+
10+
## v0.9.1
11+
12+
* module tagged with version number
13+
314
## v0.9.0
415

516
* ReadMe.md file extended and restructured a bit.

cmd/TCOBSv1CDecode/main.go

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"log"
7+
"os"
8+
9+
tcobs "github.com/rokath/tcobs/v1"
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 decode a TCOBSv1 sequence.")
35+
fmt.Fprintln(w, "Example: `echo 64 1 2 18 88 25 88 161 | TCOBSv1Decode` will return `0 0 1 2 2 2 2 88 88 88 88 88 88`")
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.CDecode(o, i)
50+
if count < 0 {
51+
log.Fatal("invalid input data, error code ", count)
52+
}
53+
o = o[len(o)-count:]
54+
for _, b := range o {
55+
fmt.Fprintf(w, "%d ", b)
56+
}
57+
return
58+
}
59+
if err != nil {
60+
log.Fatal(err, " at position ", pos)
61+
}
62+
i = append(i, n)
63+
pos++
64+
}
65+
}

cmd/TCOBSv1Encode/main.go renamed to cmd/TCOBSv1CEncode/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
"os"
88

9-
tcobs "github.com/rokath/tcobs/Cv1"
9+
tcobs "github.com/rokath/tcobs/v1"
1010
"github.com/spf13/afero"
1111
)
1212

cmd/TCOBSv1Decode/main.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
"os"
88

9-
tcobs "github.com/rokath/tcobs/Cv1"
9+
tcobs "github.com/rokath/tcobs/v1"
1010
"github.com/spf13/afero"
1111
)
1212

@@ -46,7 +46,10 @@ func doit(w io.Writer, fSys *afero.Afero) {
4646
if len(i)+31/len(i) > len(o) {
4747
log.Fatal("len of internal buffer too small")
4848
}
49-
count := tcobs.CDecode(o, i)
49+
count, e := tcobs.Decode(o, i)
50+
if e != nil {
51+
log.Fatal(e)
52+
}
5053
o = o[len(o)-count:]
5154
for _, b := range o {
5255
fmt.Fprintf(w, "%d ", b)

cmd/TCOBSv2Decode/main.go renamed to cmd/TCOBSv2CDecode/main.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
"os"
88

9-
tcobs "github.com/rokath/tcobs/Cv2"
9+
tcobs "github.com/rokath/tcobs/v2"
1010
"github.com/spf13/afero"
1111
)
1212

@@ -47,6 +47,9 @@ func doit(w io.Writer, fSys *afero.Afero) {
4747
log.Fatal("len of internal buffer too small")
4848
}
4949
count := tcobs.CDecode(o, i)
50+
if count < 0 {
51+
log.Fatal("invalid input data, error code ", count)
52+
}
5053
o = o[len(o)-count:]
5154
for _, b := range o {
5255
fmt.Fprintf(w, "%d ", b)

cmd/TCOBSv2Encode/main.go renamed to cmd/TCOBSv2CEncode/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
"os"
88

9-
tcobs "github.com/rokath/tcobs/Cv2"
9+
tcobs "github.com/rokath/tcobs/v2"
1010
"github.com/spf13/afero"
1111
)
1212

v1/read_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"io"
88
"testing"
99

10-
tcobs "github.com/rokath/tcobs/Cv1"
10+
tcobs "github.com/rokath/tcobs/v1"
1111
"github.com/stretchr/testify/assert"
1212
)
1313

v1/tcobs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"math/rand"
99
"testing"
1010

11-
tcobs "github.com/rokath/tcobs/Cv1"
11+
tcobs "github.com/rokath/tcobs/v1"
1212
"github.com/tj/assert"
1313
)
1414

v1/write_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"testing"
66

7-
tcobs "github.com/rokath/tcobs/Cv1"
7+
tcobs "github.com/rokath/tcobs/v1"
88
"github.com/stretchr/testify/assert"
99
)
1010

v2/data_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package tcobsv2_test
33
import (
44
"testing"
55

6-
tcobs "github.com/rokath/tcobs/Cv2"
6+
tcobs "github.com/rokath/tcobs/v2"
77
"github.com/stretchr/testify/assert"
88
)
99

v2/read_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"io"
88
"testing"
99

10-
tcobs "github.com/rokath/tcobs/Cv2"
10+
tcobs "github.com/rokath/tcobs/v2"
1111
"github.com/stretchr/testify/assert"
1212
)
1313

v2/tcobs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"math/rand"
88
"testing"
99

10-
tcobs "github.com/rokath/tcobs/Cv2"
10+
tcobs "github.com/rokath/tcobs/v2"
1111
"github.com/tj/assert"
1212
)
1313

v2/write_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"testing"
66

7-
tcobs "github.com/rokath/tcobs/Cv2"
7+
tcobs "github.com/rokath/tcobs/v2"
88
"github.com/stretchr/testify/assert"
99
)
1010

0 commit comments

Comments
 (0)