Explain me please what does it mean [][]byte

(Akezhan Esbolatov) #1

s := [][]byte{[]byte(“foo”), []byte(“bar”), []byte(“baz”)}

is it a 2D Slice ( slice of slices)
first of all it converts foo, bar, baz into slice of bytes and after that it converts it into slice one more time?

(Curtis Allyn Green) #2

It’s a slice of byte slices. So each element of the slice is a byte slice.

Some string manipulations operate on byte slices, doing something like this you could feed a lot of inputs to a variadic function.

(Akezhan Esbolatov) #3

and what is the difference between []byte() and []byte{}

(Norbert Melzer) #4

[]byte() does convert data that can be converted into a []byte (eg. strings), while []byte{} creates an slice of bytes, with each given “argument” as an element of it.

[]byte("foobar") == []byte{102, 111, 111, 98, 97, 114}