On Sat, Mar 27, 2021 at 6:55 PM Perry Couprie <[email protected]> wrote:
> I created the following test code. To isolate the compile error. > > Why do i get the error message : > > cannot use messageBody (type []byte) as type byte in append. > Because the append function takes a variadic list of of elements to append, not a slice. See https://golang.org/ref/spec#Appending_and_copying_slices. > func encodeMessage(messageBody []byte) ([]byte) { > > tmp,_ := hex.DecodeString(fmt.Sprintf("AB000300000000007F0100")) > > DataResponse := append(tmp, messageBody) > Try DataResponse := append(tmp, messageBody...) Although that is probably not the most efficient solution. See, for example, bytes.Buffer <https://golang.org/pkg/bytes/>. -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD_WcZv6AF2%2BYErBkN9Hjs0GLxA85o2k4MJHGzXUGtbVHA%40mail.gmail.com.
