github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/internal/unsafecast/unsafecast_go17.go (about)

     1  //go:build !go1.18
     2  
     3  package unsafecast
     4  
     5  import (
     6  	"reflect"
     7  	"unsafe"
     8  )
     9  
    10  func AddressOfBytes(data []byte) *byte {
    11  	return *(**byte)(unsafe.Pointer(&data))
    12  }
    13  
    14  func AddressOfString(data string) *byte {
    15  	return *(**byte)(unsafe.Pointer(&data))
    16  }
    17  
    18  func PointerOfValue(value reflect.Value) unsafe.Pointer {
    19  	return (*[2]unsafe.Pointer)(unsafe.Pointer(&value))[1]
    20  }
    21  
    22  func BoolToBytes(data []bool) []byte {
    23  	return unsafe.Slice(*(**byte)(unsafe.Pointer(&data)), len(data))
    24  }
    25  
    26  func Int8ToBytes(data []int8) []byte {
    27  	return unsafe.Slice(*(**byte)(unsafe.Pointer(&data)), len(data))
    28  }
    29  
    30  func Int16ToBytes(data []int16) []byte {
    31  	return unsafe.Slice(*(**byte)(unsafe.Pointer(&data)), 2*len(data))
    32  }
    33  
    34  func Int32ToBytes(data []int32) []byte {
    35  	return unsafe.Slice(*(**byte)(unsafe.Pointer(&data)), 4*len(data))
    36  }
    37  
    38  func Int64ToBytes(data []int64) []byte {
    39  	return unsafe.Slice(*(**byte)(unsafe.Pointer(&data)), 8*len(data))
    40  }
    41  
    42  func Float32ToBytes(data []float32) []byte {
    43  	return unsafe.Slice(*(**byte)(unsafe.Pointer(&data)), 4*len(data))
    44  }
    45  
    46  func Float64ToBytes(data []float64) []byte {
    47  	return unsafe.Slice(*(**byte)(unsafe.Pointer(&data)), 8*len(data))
    48  }
    49  
    50  func Int16ToUint16(data []int16) []uint16 {
    51  	return unsafe.Slice(*(**uint16)(unsafe.Pointer(&data)), len(data))
    52  }
    53  
    54  func Int32ToUint32(data []int32) []uint32 {
    55  	return unsafe.Slice(*(**uint32)(unsafe.Pointer(&data)), len(data))
    56  }
    57  
    58  func Int64ToUint64(data []int64) []uint64 {
    59  	return unsafe.Slice(*(**uint64)(unsafe.Pointer(&data)), len(data))
    60  }
    61  
    62  func Float32ToUint32(data []float32) []uint32 {
    63  	return unsafe.Slice(*(**uint32)(unsafe.Pointer(&data)), len(data))
    64  }
    65  
    66  func Float64ToUint64(data []float64) []uint64 {
    67  	return unsafe.Slice(*(**uint64)(unsafe.Pointer(&data)), len(data))
    68  }
    69  
    70  func Uint32ToBytes(data []uint32) []byte {
    71  	return unsafe.Slice(*(**byte)(unsafe.Pointer(&data)), 4*len(data))
    72  }
    73  
    74  func Uint64ToBytes(data []uint64) []byte {
    75  	return unsafe.Slice(*(**byte)(unsafe.Pointer(&data)), 8*len(data))
    76  }
    77  
    78  func Uint128ToBytes(data [][16]byte) []byte {
    79  	return unsafe.Slice(*(**byte)(unsafe.Pointer(&data)), 16*len(data))
    80  }
    81  
    82  func Uint32ToInt32(data []uint32) []int32 {
    83  	return unsafe.Slice(*(**int32)(unsafe.Pointer(&data)), len(data))
    84  }
    85  
    86  func Uint32ToInt64(data []uint32) []int64 {
    87  	return unsafe.Slice(*(**int64)(unsafe.Pointer(&data)), len(data)/2)
    88  }
    89  
    90  func Uint64ToInt64(data []uint64) []int64 {
    91  	return unsafe.Slice(*(**int64)(unsafe.Pointer(&data)), len(data))
    92  }
    93  
    94  func BytesToBool(data []byte) []bool {
    95  	return unsafe.Slice(*(**bool)(unsafe.Pointer(&data)), len(data))
    96  }
    97  
    98  func BytesToInt8(data []byte) []int8 {
    99  	return unsafe.Slice(*(**int8)(unsafe.Pointer(&data)), len(data))
   100  }
   101  
   102  func BytesToInt16(data []byte) []int16 {
   103  	return unsafe.Slice(*(**int16)(unsafe.Pointer(&data)), len(data)/2)
   104  }
   105  
   106  func BytesToInt32(data []byte) []int32 {
   107  	return unsafe.Slice(*(**int32)(unsafe.Pointer(&data)), len(data)/4)
   108  }
   109  
   110  func BytesToInt64(data []byte) []int64 {
   111  	return unsafe.Slice(*(**int64)(unsafe.Pointer(&data)), len(data)/8)
   112  }
   113  
   114  func BytesToUint32(data []byte) []uint32 {
   115  	return unsafe.Slice(*(**uint32)(unsafe.Pointer(&data)), len(data)/4)
   116  }
   117  
   118  func BytesToUint64(data []byte) []uint64 {
   119  	return unsafe.Slice(*(**uint64)(unsafe.Pointer(&data)), len(data)/8)
   120  }
   121  
   122  func BytesToUint128(data []byte) [][16]byte {
   123  	return unsafe.Slice(*(**[16]byte)(unsafe.Pointer(&data)), len(data)/16)
   124  }
   125  
   126  func BytesToFloat32(data []byte) []float32 {
   127  	return unsafe.Slice(*(**float32)(unsafe.Pointer(&data)), len(data)/4)
   128  }
   129  
   130  func BytesToFloat64(data []byte) []float64 {
   131  	return unsafe.Slice(*(**float64)(unsafe.Pointer(&data)), len(data)/8)
   132  }
   133  
   134  func BytesToString(data []byte) string {
   135  	return *(*string)(unsafe.Pointer(&data))
   136  }