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