forked from francoispqt/gojay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (42 loc) · 762 Bytes
/
main.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
package fuzz
import (
"github.com/francoispqt/gojay"
)
type user struct {
id int
created uint64
age float64
name string
email string
friend *user
}
// implement gojay.UnmarshalerJSONObject
func (u *user) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
switch key {
case "id":
return dec.Int(&u.id)
case "created":
return dec.Uint64(&u.created)
case "age":
return dec.Float(&u.age)
case "name":
return dec.String(&u.name)
case "email":
return dec.String(&u.email)
case "friend":
uu := &user{}
return dec.Object(uu)
}
return nil
}
func (u *user) NKeys() int {
return 3
}
func Fuzz(input []byte) int {
u := &user{}
err := gojay.UnmarshalJSONObject(input, u)
if err != nil {
return 0
}
return 1
}