telebit/mplexer/packer/packer.go

18 lines
378 B
Go
Raw Normal View History

2020-05-18 08:43:06 +00:00
package packer
import (
2020-05-18 09:30:22 +00:00
"fmt"
2020-05-18 08:43:06 +00:00
)
2020-05-18 09:30:22 +00:00
func Encode(src, dst Addr, domain string, payload []byte) ([]byte, []byte, error) {
n := len(payload)
header := []byte(fmt.Sprintf(
"%s,%s,%d,%d,%s,%d,%s,\n",
src.family, src.addr, src.port,
n, dst.scheme, dst.port, domain,
))
2020-05-18 08:43:06 +00:00
raw := []byte{255 - 1, byte(len(header))}
header = append(raw, header...)
2020-05-18 09:30:22 +00:00
return header, payload, nil
2020-05-18 08:43:06 +00:00
}