summaryrefslogtreecommitdiff
path: root/pkg/server/module/hex.go
blob: 9b80e0d7a1e337f417eb75c046be5871ebd18339 (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() {
	registerPipe("hex", Pipe(hexEncoder))
	registerPipe("unhex", Pipe(hexDecoder))
}