I have slices of different types, and I need to send them with TCP. The length of my slices is large, and not a constant value. Is there any way that I can convert the slices into []byte without looping through individual elements? For example, I want something like this (assuming mySlice elements are 4 Bytes here):
byteSlice := (*[4 * len(mySlice)]byte)(unsafe.Pointer(&mySlice[0]))
but it won't work, since 4 * len(mySlice)
is not a constant.
Thank you.