github.com/myafeier/go-ethereum@v1.6.8-0.20170719123245-3e0dbe0eaa72/whisper/whisperv5/gen_message_json.go (about)

     1  // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
     2  
     3  package whisperv5
     4  
     5  import (
     6  	"encoding/json"
     7  
     8  	"github.com/ethereum/go-ethereum/common/hexutil"
     9  )
    10  
    11  func (m Message) MarshalJSON() ([]byte, error) {
    12  	type Message struct {
    13  		Sig       hexutil.Bytes `json:"sig,omitempty"`
    14  		TTL       uint32        `json:"ttl"`
    15  		Timestamp uint32        `json:"timestamp"`
    16  		Topic     TopicType     `json:"topic"`
    17  		Payload   hexutil.Bytes `json:"payload"`
    18  		Padding   hexutil.Bytes `json:"padding"`
    19  		PoW       float64       `json:"pow"`
    20  		Hash      hexutil.Bytes `json:"hash"`
    21  		Dst       hexutil.Bytes `json:"recipientPublicKey,omitempty"`
    22  	}
    23  	var enc Message
    24  	enc.Sig = m.Sig
    25  	enc.TTL = m.TTL
    26  	enc.Timestamp = m.Timestamp
    27  	enc.Topic = m.Topic
    28  	enc.Payload = m.Payload
    29  	enc.Padding = m.Padding
    30  	enc.PoW = m.PoW
    31  	enc.Hash = m.Hash
    32  	enc.Dst = m.Dst
    33  	return json.Marshal(&enc)
    34  }
    35  
    36  func (m *Message) UnmarshalJSON(input []byte) error {
    37  	type Message struct {
    38  		Sig       hexutil.Bytes `json:"sig,omitempty"`
    39  		TTL       *uint32       `json:"ttl"`
    40  		Timestamp *uint32       `json:"timestamp"`
    41  		Topic     *TopicType    `json:"topic"`
    42  		Payload   hexutil.Bytes `json:"payload"`
    43  		Padding   hexutil.Bytes `json:"padding"`
    44  		PoW       *float64      `json:"pow"`
    45  		Hash      hexutil.Bytes `json:"hash"`
    46  		Dst       hexutil.Bytes `json:"recipientPublicKey,omitempty"`
    47  	}
    48  	var dec Message
    49  	if err := json.Unmarshal(input, &dec); err != nil {
    50  		return err
    51  	}
    52  	if dec.Sig != nil {
    53  		m.Sig = dec.Sig
    54  	}
    55  	if dec.TTL != nil {
    56  		m.TTL = *dec.TTL
    57  	}
    58  	if dec.Timestamp != nil {
    59  		m.Timestamp = *dec.Timestamp
    60  	}
    61  	if dec.Topic != nil {
    62  		m.Topic = *dec.Topic
    63  	}
    64  	if dec.Payload != nil {
    65  		m.Payload = dec.Payload
    66  	}
    67  	if dec.Padding != nil {
    68  		m.Padding = dec.Padding
    69  	}
    70  	if dec.PoW != nil {
    71  		m.PoW = *dec.PoW
    72  	}
    73  	if dec.Hash != nil {
    74  		m.Hash = dec.Hash
    75  	}
    76  	if dec.Dst != nil {
    77  		m.Dst = dec.Dst
    78  	}
    79  	return nil
    80  }