Skip to content

Commit a109f08

Browse files
authored
Enhancement: implement xxh32 and xxh128, refactor xxh64 (#67)
* rewired xxh64,added xxh32 and xxh128 * added tests for xxh32 and xxh128 * added processors and generated xxh32,xxh128 files * update: xxhash features * removed extra space
1 parent 459c5a8 commit a109f08

File tree

8 files changed

+370
-4
lines changed

8 files changed

+370
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ echo "Hello World" | sttr base64-encode | sttr md5
216216
- [x] **sha1** - Get the SHA1 checksum of your text
217217
- [x] **sha256** - Get the SHA256 checksum of your text
218218
- [x] **sha512** - Get the SHA512 checksum of your text
219+
- [x] **xxh32** - Get the XXH32 checksum of your text
219220
- [x] **xxh64** - Get the XXH64 checksum of your text
221+
- [x] **xxh128** - Get the XXH128 checksum of your text
220222
221223
#### String
222224

cmd/processor_xxh-128.go

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/processor_xxh-32.go

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/abhimanyu003/sttr
22

3-
go 1.24.0
3+
go 1.24.5
44

55
require (
66
github.com/cespare/xxhash/v2 v2.3.0
@@ -29,7 +29,9 @@ require (
2929
github.com/charmbracelet/x/term v0.2.1 // indirect
3030
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
3131
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
32+
github.com/harsh16coder/xxhash v1.0.1 // indirect
3233
github.com/inconshreveable/mousetrap v1.1.0 // indirect
34+
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
3335
github.com/mattn/go-isatty v0.0.20 // indirect
3436
github.com/mattn/go-localereader v0.0.1 // indirect
3537
github.com/mattn/go-runewidth v0.0.16 // indirect
@@ -43,6 +45,7 @@ require (
4345
github.com/stretchr/testify v1.11.0 // indirect
4446
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
4547
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
48+
github.com/zeebo/xxh3 v1.0.2 // indirect
4649
golang.org/x/net v0.43.0 // indirect
4750
golang.org/x/sync v0.16.0 // indirect
4851
golang.org/x/sys v0.35.0 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6
3131
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
3232
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
3333
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
34+
github.com/harsh16coder/xxhash v1.0.1 h1:t1+rlu5JDZW+RAfvieiUREMI5MP1xUeES9ju5SDQgSc=
35+
github.com/harsh16coder/xxhash v1.0.1/go.mod h1:42HodZdpLmoDzGLo5dUX4erO7mrpn4IunB5PMW5lq+w=
3436
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
3537
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
3638
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3739
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
40+
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
41+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
3842
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
3943
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
4044
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
@@ -77,6 +81,8 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM
7781
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
7882
github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA=
7983
github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
84+
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
85+
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
8086
gitlab.com/abhimanyusharma003/go-ordered-json v0.0.0-20200508150302-7ef32eef8ead h1:JzI8XDh2gVmJqe5n+F2MHhxGpL9efc4ZgBjXpY6fDrs=
8187
gitlab.com/abhimanyusharma003/go-ordered-json v0.0.0-20200508150302-7ef32eef8ead/go.mod h1:rzwdkxQuwcyF+elCTRk7kbXOI7Bj/UkmDDIhjPOrvdw=
8288
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=

processors/processor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ var List = []list.Item{
6464
Upper{},
6565
URLDecode{},
6666
URLEncode{},
67-
YAMLToJSON{},
67+
XXH32{},
6868
XXH64{},
69+
XXH128{},
70+
YAMLToJSON{},
6971
Zeropad{},
7072
}
7173

processors/xxhash.go

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package processors
33
import (
44
"fmt"
55

6-
"github.com/cespare/xxhash/v2"
6+
"github.com/harsh16coder/xxhash"
77
)
88

9+
// XXH64 encodes string to XXH64
910
type XXH64 struct{}
1011

1112
func (x XXH64) Name() string {
@@ -17,7 +18,7 @@ func (x XXH64) Alias() []string {
1718
}
1819

1920
func (x XXH64) Transform(data []byte, _ ...Flag) (string, error) {
20-
h := xxhash.New()
21+
h := xxhash.New64()
2122
if _, err := h.Write(data); err != nil {
2223
return "", err
2324
}
@@ -41,3 +42,77 @@ func (x XXH64) Description() string {
4142
func (x XXH64) FilterValue() string {
4243
return x.Title()
4344
}
45+
46+
// XX32 encodes string to XXH32
47+
type XXH32 struct{}
48+
49+
func (x XXH32) Name() string {
50+
return "xxh-32"
51+
}
52+
53+
func (x XXH32) Alias() []string {
54+
return []string{"xxh32", "xxhash32", "xxhash-32"}
55+
}
56+
57+
func (x XXH32) Transform(data []byte, _ ...Flag) (string, error) {
58+
h := xxhash.New32()
59+
if _, err := h.Write(data); err != nil {
60+
return "", err
61+
}
62+
s := h.Sum32()
63+
return fmt.Sprintf("%08x", s), nil
64+
}
65+
66+
func (x XXH32) Flags() []Flag {
67+
return nil
68+
}
69+
70+
func (x XXH32) Title() string {
71+
title := "xxHash - XXH32"
72+
return fmt.Sprintf("%s (%s)", title, x.Name())
73+
}
74+
75+
func (x XXH32) Description() string {
76+
return "Get the XXH32 checksum of your text"
77+
}
78+
79+
func (x XXH32) FilterValue() string {
80+
return x.Title()
81+
}
82+
83+
// XX128 encodes string to XXH32
84+
type XXH128 struct{}
85+
86+
func (x XXH128) Name() string {
87+
return "xxh-128"
88+
}
89+
90+
func (x XXH128) Alias() []string {
91+
return []string{"xxh128", "xxhash128", "xxhash-128"}
92+
}
93+
94+
func (x XXH128) Transform(data []byte, _ ...Flag) (string, error) {
95+
h := xxhash.New128()
96+
if _, err := h.Write(data); err != nil {
97+
return "", err
98+
}
99+
s := h.Sum128()
100+
return fmt.Sprintf("%016x%016x", s.Hi, s.Lo), nil
101+
}
102+
103+
func (x XXH128) Flags() []Flag {
104+
return nil
105+
}
106+
107+
func (x XXH128) Title() string {
108+
title := "xxHash - XXH128"
109+
return fmt.Sprintf("%s (%s)", title, x.Name())
110+
}
111+
112+
func (x XXH128) Description() string {
113+
return "Get the XXH128 checksum of your text"
114+
}
115+
116+
func (x XXH128) FilterValue() string {
117+
return x.Title()
118+
}

0 commit comments

Comments
 (0)