generated from rokath/Best-README-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
499 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.