blob: daa8d7692ae0cabb9447b57825853a746c5034b3 [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301//go:build !appengine
2// +build !appengine
3
4package util
5
6import (
7 "unsafe"
8)
9
10// BytesToString converts byte slice to string.
11func BytesToString(b []byte) string {
12 return *(*string)(unsafe.Pointer(&b))
13}
14
15// StringToBytes converts string to byte slice.
16func StringToBytes(s string) []byte {
17 return *(*[]byte)(unsafe.Pointer(
18 &struct {
19 string
20 Cap int
21 }{s, len(s)},
22 ))
23}