2019-08-22 11:27:18 +02:00
|
|
|
package fastjson
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
func b2s(b []byte) string {
|
|
|
|
return *(*string)(unsafe.Pointer(&b))
|
|
|
|
}
|
|
|
|
|
2020-08-05 10:53:41 +02:00
|
|
|
func s2b(s string) (b []byte) {
|
2019-08-22 11:27:18 +02:00
|
|
|
strh := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
2020-08-05 10:53:41 +02:00
|
|
|
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
2019-08-22 11:27:18 +02:00
|
|
|
sh.Data = strh.Data
|
|
|
|
sh.Len = strh.Len
|
|
|
|
sh.Cap = strh.Len
|
2020-08-05 10:53:41 +02:00
|
|
|
return b
|
2019-08-22 11:27:18 +02: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
|
|
|
|
}
|