mirror of
https://github.com/containers/podman.git
synced 2025-05-22 17:46:52 +08:00
23 lines
482 B
Go
23 lines
482 B
Go
package swag
|
|
|
|
import "unsafe"
|
|
|
|
type internalString struct {
|
|
Data unsafe.Pointer
|
|
Len int
|
|
}
|
|
|
|
// hackStringBytes returns the (unsafe) underlying bytes slice of a string.
|
|
func hackStringBytes(str string) []byte {
|
|
p := (*internalString)(unsafe.Pointer(&str)).Data
|
|
return unsafe.Slice((*byte)(p), len(str))
|
|
}
|
|
|
|
/*
|
|
* go1.20 version (for when go mod moves to a go1.20 requirement):
|
|
|
|
func hackStringBytes(str string) []byte {
|
|
return unsafe.Slice(unsafe.StringData(str), len(str))
|
|
}
|
|
*/
|