-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuint32.go
106 lines (93 loc) · 2.17 KB
/
uint32.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package nullable
// Do not modify. Generated by nullable-generate.
import (
"bytes"
"database/sql"
"database/sql/driver"
"encoding/json"
)
// Uint32 represents a uint32 value that may be null.
// This type implements the Scanner interface so it
// can be used as a scan destination, similar to NullString.
// It also implements the necessary interfaces to serialize
// to and from JSON.
type Uint32 struct {
Uint32 uint32
Valid bool
}
// Uint32FromPtr returns a Uint32 whose value matches ptr.
func Uint32FromPtr(ptr *uint32) Uint32 {
var v Uint32
return v.Assign(ptr)
}
// Assign the value of the pointer. If the pointer is nil,
// then then Valid is false, otherwise Valid is true.
func (n *Uint32) Assign(ptr *uint32) Uint32 {
if ptr == nil {
n.Valid = false
n.Uint32 = 0
} else {
n.Valid = true
n.Uint32 = *ptr
}
return *n
}
// Ptr returns a pointer to uint32. If Valid is false
// then the pointer is nil, otherwise it is non-nil.
func (n Uint32) Ptr() *uint32 {
if n.Valid {
v := n.Uint32
return &v
}
return nil
}
// Normalized returns a Uint32 that can be compared with
// another Uint32 for equality.
func (n Uint32) Normalized() Uint32 {
if n.Valid {
return n
}
// If !Valid, then Uint32 could be any value.
// Normalized value can be compared for equality.
return Uint32{}
}
// Scan implements the sql.Scanner interface.
func (n *Uint32) Scan(value interface{}) error {
var nt sql.NullInt64
err := nt.Scan(value)
if err != nil {
return err
}
n.Valid = nt.Valid
n.Uint32 = uint32(nt.Int64)
return nil
}
// Value implements the driver.Valuer interface.
func (n Uint32) Value() (driver.Value, error) {
if !n.Valid {
return nil, nil
}
return int64(n.Uint32), nil
}
// MarshalJSON implements the json.Marshaler interface.
func (n Uint32) MarshalJSON() ([]byte, error) {
if n.Valid {
return json.Marshal(n.Uint32)
}
return []byte("null"), nil
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (n *Uint32) UnmarshalJSON(p []byte) error {
if bytes.Equal(p, jsonNull) {
n.Uint32 = 0
n.Valid = false
return nil
}
var v uint32
if err := json.Unmarshal(p, &v); err != nil {
return err
}
n.Uint32 = v
n.Valid = true
return nil
}