mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-11 14:53:49 +00:00
30 lines
520 B
Go
30 lines
520 B
Go
package fastjson
|
|
|
|
import (
|
|
"reflect"
|
|
"unsafe"
|
|
)
|
|
|
|
func b2s(b []byte) string {
|
|
return *(*string)(unsafe.Pointer(&b))
|
|
}
|
|
|
|
func s2b(s string) (b []byte) {
|
|
strh := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
|
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
|
sh.Data = strh.Data
|
|
sh.Len = strh.Len
|
|
sh.Cap = strh.Len
|
|
return b
|
|
}
|
|
|
|
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
|
|
}
|