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