github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/whisper/whisperv6/gen_criteria_json.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:46</date> 10 //</624450125434982400> 11 12 //代码由github.com/fjl/gencodec生成。不要编辑。 13 14 package whisperv6 15 16 import ( 17 "encoding/json" 18 19 "github.com/ethereum/go-ethereum/common/hexutil" 20 ) 21 22 var _ = (*criteriaOverride)(nil) 23 24 //marshaljson将类型条件封送到json字符串 25 func (c Criteria) MarshalJSON() ([]byte, error) { 26 type Criteria struct { 27 SymKeyID string `json:"symKeyID"` 28 PrivateKeyID string `json:"privateKeyID"` 29 Sig hexutil.Bytes `json:"sig"` 30 MinPow float64 `json:"minPow"` 31 Topics []TopicType `json:"topics"` 32 AllowP2P bool `json:"allowP2P"` 33 } 34 var enc Criteria 35 enc.SymKeyID = c.SymKeyID 36 enc.PrivateKeyID = c.PrivateKeyID 37 enc.Sig = c.Sig 38 enc.MinPow = c.MinPow 39 enc.Topics = c.Topics 40 enc.AllowP2P = c.AllowP2P 41 return json.Marshal(&enc) 42 } 43 44 //将JSON的类型条件取消标记为JSON字符串 45 func (c *Criteria) UnmarshalJSON(input []byte) error { 46 type Criteria struct { 47 SymKeyID *string `json:"symKeyID"` 48 PrivateKeyID *string `json:"privateKeyID"` 49 Sig *hexutil.Bytes `json:"sig"` 50 MinPow *float64 `json:"minPow"` 51 Topics []TopicType `json:"topics"` 52 AllowP2P *bool `json:"allowP2P"` 53 } 54 var dec Criteria 55 if err := json.Unmarshal(input, &dec); err != nil { 56 return err 57 } 58 if dec.SymKeyID != nil { 59 c.SymKeyID = *dec.SymKeyID 60 } 61 if dec.PrivateKeyID != nil { 62 c.PrivateKeyID = *dec.PrivateKeyID 63 } 64 if dec.Sig != nil { 65 c.Sig = *dec.Sig 66 } 67 if dec.MinPow != nil { 68 c.MinPow = *dec.MinPow 69 } 70 if dec.Topics != nil { 71 c.Topics = dec.Topics 72 } 73 if dec.AllowP2P != nil { 74 c.AllowP2P = *dec.AllowP2P 75 } 76 return nil 77 } 78