summaryrefslogtreecommitdiff
path: root/pkg/server/module/hex.go
blob: b632c119148f2c14d9e293d8e04ad2e22a710360 (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 (
	"encoding/hex"
	"tunnel/pkg/server/queue"
)

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() {
	registerPipe("hex", Pipe(hexEncoder))
	registerPipe("unhex", Pipe(hexDecoder))
}