3 Star 0 Fork 0

neuro-netw0rk/server-golib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
async_task
captcha
code
config
constant
core
db
errors
jwt
k8s
log
message
middleware/http
minio
nlog
permission
redis
server
shutdown
utils
extend
generics
metadata
aes.go
bufferpool.go
bufferpool_test.go
bytesconv.go
conf.go
context.go
copier.go
device.go
email.go
encrypt.go
encrypt_test.go
file.go
id_crypt.go
id_crypt_test.go
net.go
php_internal.go
php_internal_test.go
string.go
struct.go
targz.go
targz_test.go
time.go
utils.go
uuid.go
version.go
xor.go
zip.go
.gitignore
LICENSE
README.en.md
README.md
go.mod
todo.list
克隆/下载
bytesconv.go 487 Bytes
一键复制 编辑 原始数据 按行查看 历史
LeoWang 提交于 7个月前 . 整合golib和serverlib
package utils
import (
"reflect"
"unsafe"
)
// StringToBytes converts string to byte slice without a memory allocation.
func StringToBytes(s string) (b []byte) {
sh := *(*reflect.StringHeader)(unsafe.Pointer(&s))
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
bh.Data, bh.Len, bh.Cap = sh.Data, sh.Len, sh.Len
return b
}
// BytesToString converts byte slice to string without a memory allocation.
func BytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/neuro-netw0rk/server-golib.git
git@gitee.com:neuro-netw0rk/server-golib.git
neuro-netw0rk
server-golib
server-golib
v0.0.5-beta2

搜索帮助