github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/whisper/whisperv6/gen_message_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 whisperv6 12 13 import ( 14 "encoding/json" 15 16 "github.com/ethereum/go-ethereum/common/hexutil" 17 ) 18 19 var _ = (*messageOverride)(nil) 20 21 // 22 func (m Message) MarshalJSON() ([]byte, error) { 23 type Message struct { 24 Sig hexutil.Bytes `json:"sig,omitempty"` 25 TTL uint32 `json:"ttl"` 26 Timestamp uint32 `json:"timestamp"` 27 Topic TopicType `json:"topic"` 28 Payload hexutil.Bytes `json:"payload"` 29 Padding hexutil.Bytes `json:"padding"` 30 PoW float64 `json:"pow"` 31 Hash hexutil.Bytes `json:"hash"` 32 Dst hexutil.Bytes `json:"recipientPublicKey,omitempty"` 33 } 34 var enc Message 35 enc.Sig = m.Sig 36 enc.TTL = m.TTL 37 enc.Timestamp = m.Timestamp 38 enc.Topic = m.Topic 39 enc.Payload = m.Payload 40 enc.Padding = m.Padding 41 enc.PoW = m.PoW 42 enc.Hash = m.Hash 43 enc.Dst = m.Dst 44 return json.Marshal(&enc) 45 } 46 47 // 48 func (m *Message) UnmarshalJSON(input []byte) error { 49 type Message struct { 50 Sig *hexutil.Bytes `json:"sig,omitempty"` 51 TTL *uint32 `json:"ttl"` 52 Timestamp *uint32 `json:"timestamp"` 53 Topic *TopicType `json:"topic"` 54 Payload *hexutil.Bytes `json:"payload"` 55 Padding *hexutil.Bytes `json:"padding"` 56 PoW *float64 `json:"pow"` 57 Hash *hexutil.Bytes `json:"hash"` 58 Dst *hexutil.Bytes `json:"recipientPublicKey,omitempty"` 59 } 60 var dec Message 61 if err := json.Unmarshal(input, &dec); err != nil { 62 return err 63 } 64 if dec.Sig != nil { 65 m.Sig = *dec.Sig 66 } 67 if dec.TTL != nil { 68 m.TTL = *dec.TTL 69 } 70 if dec.Timestamp != nil { 71 m.Timestamp = *dec.Timestamp 72 } 73 if dec.Topic != nil { 74 m.Topic = *dec.Topic 75 } 76 if dec.Payload != nil { 77 m.Payload = *dec.Payload 78 } 79 if dec.Padding != nil { 80 m.Padding = *dec.Padding 81 } 82 if dec.PoW != nil { 83 m.PoW = *dec.PoW 84 } 85 if dec.Hash != nil { 86 m.Hash = *dec.Hash 87 } 88 if dec.Dst != nil { 89 m.Dst = *dec.Dst 90 } 91 return nil 92 }