gen_message_json.go 2.0 KB

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