Add test cases and start client

This commit is contained in:
Bolke de Bruin 2020-07-29 13:45:08 +02:00
parent dadaeb611b
commit 5618294f10
4 changed files with 162 additions and 12 deletions

View file

@ -2,6 +2,7 @@ package protocol
import (
"bytes"
"encoding/binary"
"fmt"
"unicode/utf16"
"unicode/utf8"
@ -30,3 +31,12 @@ func DecodeUTF16(b []byte) (string, error) {
}
return string(bret), nil
}
func EncodeUTF16(s string) []byte {
ret := new(bytes.Buffer)
enc := utf16.Encode([]rune(s))
for c := range enc {
binary.Write(ret, binary.LittleEndian, enc[c])
}
return ret.Bytes()
}