-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuintptr.go
33 lines (27 loc) · 788 Bytes
/
uintptr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package pretty
import (
"io"
"reflect"
"github.com/pierrre/go-libs/strconvio"
"github.com/pierrre/pretty/internal/write"
)
// UintptrValueWriter is a [ValueWriter] that handles uintptr values.
//
// It should be created with [NewUintptrValueWriter].
type UintptrValueWriter struct{}
// NewUintptrValueWriter creates a new [UintptrValueWriter].
func NewUintptrValueWriter() *UintptrValueWriter {
return &UintptrValueWriter{}
}
// WriteValue implements [ValueWriter].
func (vw *UintptrValueWriter) WriteValue(st *State, v reflect.Value) bool {
if v.Kind() != reflect.Uintptr {
return false
}
writeUintptr(st.Writer, uintptr(v.Uint()))
return true
}
func writeUintptr(w io.Writer, p uintptr) {
write.MustString(w, "0x")
write.Must(strconvio.WriteUint(w, uint64(p), 16))
}