23 lines
609 B
Go
23 lines
609 B
Go
package vector
|
|
|
|
import (
|
|
"golang.org/x/exp/slices"
|
|
"runtime"
|
|
"unsafe"
|
|
)
|
|
|
|
func Int8ToBytes(data []int8) (buf []byte) {
|
|
defer runtime.KeepAlive(data)
|
|
return slices.Clone(unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(data))), len(data)))
|
|
}
|
|
|
|
func Int16ToBytes(data []int16) (buf []byte) {
|
|
defer runtime.KeepAlive(data)
|
|
return slices.Clone(unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(data))), len(data)*2))
|
|
}
|
|
|
|
func Float32ToBytes(data []float32) (buf []byte) {
|
|
defer runtime.KeepAlive(data)
|
|
return slices.Clone(unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(data))), len(data)*4))
|
|
}
|