summaryrefslogtreecommitdiff
path: root/pkg/server/module/hex.go
blob: 2ffd1fc1284c39dd123af3a8c9c2ca3688b81b9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package module

import (
	"tunnel/pkg/server/queue"
	"encoding/hex"
)

func hexEncoder(rq, wq queue.Q) error {
	enc := hex.NewEncoder(wq.Writer())

	for b := range rq {
		enc.Write(b)
	}

	return nil
}

func hexDecoder(rq, wq queue.Q) error {
	r := hex.NewDecoder(rq.Reader())
	w := wq.Writer()
	return queue.IoCopy(r, w)
}

func init() {
	register("hex", pipe(hexEncoder))
	register("unhex", pipe(hexDecoder))
}