github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/array_go18.go (about) 1 //go:build go1.18 2 3 package parquet 4 5 import ( 6 "unsafe" 7 8 "github.com/vc42/parquet-go/internal/unsafecast" 9 "github.com/vc42/parquet-go/sparse" 10 ) 11 12 func makeArray(base unsafe.Pointer, length int, offset uintptr) sparse.Array { 13 return sparse.UnsafeArray(base, length, offset) 14 } 15 16 func makeArrayOf[T any](s []T) sparse.Array { 17 var model T 18 return makeArray(unsafecast.PointerOf(s), len(s), unsafe.Sizeof(model)) 19 } 20 21 func makeSlice[T any](a sparse.Array) []T { 22 return slice[T](a.Index(0), a.Len()) 23 } 24 25 func slice[T any](p unsafe.Pointer, n int) []T { 26 return unsafe.Slice((*T)(p), n) 27 } 28 29 type sliceHeader struct { 30 base unsafe.Pointer 31 len int 32 cap int 33 }