github.com/3andne/restls-client-go@v0.1.6/internal/helper/typeconv.go (about) 1 package helper 2 3 import ( 4 "errors" 5 6 "golang.org/x/crypto/cryptobyte" 7 ) 8 9 // Uint8to16 converts a slice of uint8 to a slice of uint16. 10 // e.g. []uint8{0x00, 0x01, 0x00, 0x02} -> []uint16{0x0001, 0x0002} 11 func Uint8to16(in []uint8) ([]uint16, error) { 12 s := cryptobyte.String(in) 13 var out []uint16 14 for !s.Empty() { 15 var v uint16 16 if s.ReadUint16(&v) { 17 out = append(out, v) 18 } else { 19 return nil, errors.New("ReadUint16 failed") 20 } 21 } 22 return out, nil 23 }