func copingMapping(fr mmap.ReaderAt) []int32 { _bytes := make([]byte, fr.Len(), fr.Len()) _, err := fr.ReadAt(_bytes, 0) if err != nil { fmt.Printf("got error msg: %s", err) } data := make([]int32, fr.Len()/4, fr.Len()/4) buf := bytes.NewBuffer(_bytes) binary.Read(buf, binary.LittleEndian, &data) return data }
func reflectionMapping(fr *mmap.ReaderAt, typeSize int) []int32 { _bytes := make([]byte, fr.Len(), fr.Len()) _, err := fr.ReadAt(_bytes, 0) if err != nil { fmt.Printf("got error msg: %s", err) } header := *(*reflect.SliceHeader)(unsafe.Pointer(&_bytes)) // The length and capacity of the slice are different. header.Len /= typeSize // 8 + 4 + 1 header.Cap /= typeSize // 8 + 4 + 1 // Convert slice header to a []byte return *(*[]int32)(unsafe.Pointer(&header)) }