github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/whisper/whisperv5/gen_newmessage_json.go (about) 1 2 //此源码被清华学神尹成大魔王专业翻译分析并修改 3 //尹成QQ77025077 4 //尹成微信18510341407 5 //尹成所在QQ群721929980 6 //尹成邮箱 yinc13@mails.tsinghua.edu.cn 7 //尹成毕业于清华大学,微软区块链领域全球最有价值专家 8 //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620 9 // 10 11 package whisperv5 12 13 import ( 14 "encoding/json" 15 16 "github.com/ethereum/go-ethereum/common/hexutil" 17 ) 18 19 var _ = (*newMessageOverride)(nil) 20 21 func (n NewMessage) MarshalJSON() ([]byte, error) { 22 type NewMessage struct { 23 SymKeyID string `json:"symKeyID"` 24 PublicKey hexutil.Bytes `json:"pubKey"` 25 Sig string `json:"sig"` 26 TTL uint32 `json:"ttl"` 27 Topic TopicType `json:"topic"` 28 Payload hexutil.Bytes `json:"payload"` 29 Padding hexutil.Bytes `json:"padding"` 30 PowTime uint32 `json:"powTime"` 31 PowTarget float64 `json:"powTarget"` 32 TargetPeer string `json:"targetPeer"` 33 } 34 var enc NewMessage 35 enc.SymKeyID = n.SymKeyID 36 enc.PublicKey = n.PublicKey 37 enc.Sig = n.Sig 38 enc.TTL = n.TTL 39 enc.Topic = n.Topic 40 enc.Payload = n.Payload 41 enc.Padding = n.Padding 42 enc.PowTime = n.PowTime 43 enc.PowTarget = n.PowTarget 44 enc.TargetPeer = n.TargetPeer 45 return json.Marshal(&enc) 46 } 47 48 func (n *NewMessage) UnmarshalJSON(input []byte) error { 49 type NewMessage struct { 50 SymKeyID *string `json:"symKeyID"` 51 PublicKey *hexutil.Bytes `json:"pubKey"` 52 Sig *string `json:"sig"` 53 TTL *uint32 `json:"ttl"` 54 Topic *TopicType `json:"topic"` 55 Payload *hexutil.Bytes `json:"payload"` 56 Padding *hexutil.Bytes `json:"padding"` 57 PowTime *uint32 `json:"powTime"` 58 PowTarget *float64 `json:"powTarget"` 59 TargetPeer *string `json:"targetPeer"` 60 } 61 var dec NewMessage 62 if err := json.Unmarshal(input, &dec); err != nil { 63 return err 64 } 65 if dec.SymKeyID != nil { 66 n.SymKeyID = *dec.SymKeyID 67 } 68 if dec.PublicKey != nil { 69 n.PublicKey = *dec.PublicKey 70 } 71 if dec.Sig != nil { 72 n.Sig = *dec.Sig 73 } 74 if dec.TTL != nil { 75 n.TTL = *dec.TTL 76 } 77 if dec.Topic != nil { 78 n.Topic = *dec.Topic 79 } 80 if dec.Payload != nil { 81 n.Payload = *dec.Payload 82 } 83 if dec.Padding != nil { 84 n.Padding = *dec.Padding 85 } 86 if dec.PowTime != nil { 87 n.PowTime = *dec.PowTime 88 } 89 if dec.PowTarget != nil { 90 n.PowTarget = *dec.PowTarget 91 } 92 if dec.TargetPeer != nil { 93 n.TargetPeer = *dec.TargetPeer 94 } 95 return nil 96 }