github.com/AndrienkoAleksandr/go@v0.0.19/src/intern/abi/unsafestring_go119.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !go1.20
     6  // +build !go1.20
     7  
     8  package abi
     9  
    10  import "unsafe"
    11  
    12  type (
    13  	stringHeader struct {
    14  		Data *byte
    15  		Len  int
    16  	}
    17  	sliceHeader struct {
    18  		Data *byte
    19  		Len  int
    20  		Cap  int
    21  	}
    22  )
    23  
    24  func unsafeStringFor(b *byte, l int) string {
    25  	h := stringHeader{Data: b, Len: l}
    26  	return *(*string)(unsafe.Pointer(&h))
    27  }
    28  
    29  func unsafeSliceFor(b *byte, l int) []byte {
    30  	h := sliceHeader{Data: b, Len: l, Cap: l}
    31  	return *(*[]byte)(unsafe.Pointer(&h))
    32  }