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