-
Notifications
You must be signed in to change notification settings - Fork 4
/
gen_config_from_file_json.go
75 lines (69 loc) · 2.45 KB
/
gen_config_from_file_json.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
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package config
import (
"encoding/json"
"errors"
"github.com/LemoFoundationLtd/lemochain-core/common/hexutil"
)
var _ = (*ConfigFromFileMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (c ConfigFromFile) MarshalJSON() ([]byte, error) {
type ConfigFromFile struct {
ChainID hexutil.Uint64 `json:"chainID" gencodec:"required"`
DeputyCount hexutil.Uint64 `json:"deputyCount" gencodec:"required"`
SleepTime hexutil.Uint64 `json:"sleepTime"`
Timeout hexutil.Uint64 `json:"timeout"`
TermDuration hexutil.Uint64 `json:"termDuration"`
InterimDuration hexutil.Uint64 `json:"interimDuration"`
ConnectionLimit hexutil.Uint64 `json:"connectionLimit"`
}
var enc ConfigFromFile
enc.ChainID = hexutil.Uint64(c.ChainID)
enc.DeputyCount = hexutil.Uint64(c.DeputyCount)
enc.SleepTime = hexutil.Uint64(c.SleepTime)
enc.Timeout = hexutil.Uint64(c.Timeout)
enc.TermDuration = hexutil.Uint64(c.TermDuration)
enc.InterimDuration = hexutil.Uint64(c.InterimDuration)
enc.ConnectionLimit = hexutil.Uint64(c.ConnectionLimit)
return json.Marshal(&enc)
}
// UnmarshalJSON unmarshals from JSON.
func (c *ConfigFromFile) UnmarshalJSON(input []byte) error {
type ConfigFromFile struct {
ChainID *hexutil.Uint64 `json:"chainID" gencodec:"required"`
DeputyCount *hexutil.Uint64 `json:"deputyCount" gencodec:"required"`
SleepTime *hexutil.Uint64 `json:"sleepTime"`
Timeout *hexutil.Uint64 `json:"timeout"`
TermDuration *hexutil.Uint64 `json:"termDuration"`
InterimDuration *hexutil.Uint64 `json:"interimDuration"`
ConnectionLimit *hexutil.Uint64 `json:"connectionLimit"`
}
var dec ConfigFromFile
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.ChainID == nil {
return errors.New("missing required field 'chainID' for ConfigFromFile")
}
c.ChainID = uint64(*dec.ChainID)
if dec.DeputyCount == nil {
return errors.New("missing required field 'deputyCount' for ConfigFromFile")
}
c.DeputyCount = uint64(*dec.DeputyCount)
if dec.SleepTime != nil {
c.SleepTime = uint64(*dec.SleepTime)
}
if dec.Timeout != nil {
c.Timeout = uint64(*dec.Timeout)
}
if dec.TermDuration != nil {
c.TermDuration = uint64(*dec.TermDuration)
}
if dec.InterimDuration != nil {
c.InterimDuration = uint64(*dec.InterimDuration)
}
if dec.ConnectionLimit != nil {
c.ConnectionLimit = uint64(*dec.ConnectionLimit)
}
return nil
}