github.com/gobitfly/go-ethereum@v1.8.12/whisper/whisperv6/gen_message_json.go (about)

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