summaryrefslogtreecommitdiffstats
path: root/src/internal/abi/unsafestring_go119.go
blob: a7103849a4b215c18c8f9b4e18d46f700a0f7602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !go1.20
// +build !go1.20

package abi

import "unsafe"

type (
	stringHeader struct {
		Data *byte
		Len  int
	}
	sliceHeader struct {
		Data *byte
		Len  int
		Cap  int
	}
)

func unsafeStringFor(b *byte, l int) string {
	h := stringHeader{Data: b, Len: l}
	return *(*string)(unsafe.Pointer(&h))
}

func unsafeSliceFor(b *byte, l int) []byte {
	h := sliceHeader{Data: b, Len: l, Cap: l}
	return *(*[]byte)(unsafe.Pointer(&h))
}