2019-08-22 09:27:18 +00:00
|
|
|
package fastjson
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
func b2s(b []byte) string {
|
|
|
|
return *(*string)(unsafe.Pointer(&b))
|
|
|
|
}
|
|
|
|
|
2020-08-05 08:53:41 +00:00
|
|
|
func s2b(s string) (b []byte) {
|
2019-08-22 09:27:18 +00:00
|
|
|
strh := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
2020-08-05 08:53:41 +00:00
|
|
|
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
2019-08-22 09:27:18 +00:00
|
|
|
sh.Data = strh.Data
|
|
|
|
sh.Len = strh.Len
|
|
|
|
sh.Cap = strh.Len
|
2020-08-05 08:53:41 +00:00
|
|
|
return b
|
2019-08-22 09:27:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const maxStartEndStringLen = 80
|
|
|
|
|
|
|
|
func startEndString(s string) string {
|
|
|
|
if len(s) <= maxStartEndStringLen {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
start := s[:40]
|
|
|
|
end := s[len(s)-40:]
|
|
|
|
return start + "..." + end
|
|
|
|
}
|