summaryrefslogtreecommitdiff
path: root/pkg/server/hook/hex.go
blob: 4d7f1e7fc4827e4657ff15b25bc6303b907dfc05 (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
28
package hook

import (
	"encoding/hex"

	"tunnel/pkg/server/queue"
)

type hexPipe struct{}

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

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

	return nil
}

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

func init() {
	registerPipe("hex", "stream hexify out/", hexPipe{})
}