-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuint.go
34 lines (29 loc) · 869 Bytes
/
uint.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
34
package pretty
import (
"reflect"
"github.com/pierrre/go-libs/strconvio"
"github.com/pierrre/pretty/internal/write"
)
// UintValueWriter is a [ValueWriter] that handles uint values.
//
// It should be created with [NewUintValueWriter].
type UintValueWriter struct {
// Base is the base used to format the integer.
// Default: 10.
Base int
}
// NewUintValueWriter creates a new [UintValueWriter] with default values.
func NewUintValueWriter() *UintValueWriter {
return &UintValueWriter{
Base: 10,
}
}
// WriteValue implements [ValueWriter].
func (vw *UintValueWriter) WriteValue(st *State, v reflect.Value) bool {
switch v.Kind() { //nolint:exhaustive // Only handles uint.
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
write.Must(strconvio.WriteUint(st.Writer, v.Uint(), vw.Base))
return true
}
return false
}