aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv5/gen_message_json.go
blob: 26168225c93236628abfc7b77ed0a70ce08dcfa1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.

package whisperv5

import (
    "encoding/json"

    "github.com/ethereum/go-ethereum/common/hexutil"
)

func (m Message) MarshalJSON() ([]byte, error) {
    type Message struct {
        Sig       hexutil.Bytes `json:"sig,omitempty"`
        TTL       uint32        `json:"ttl"`
        Timestamp uint32        `json:"timestamp"`
        Topic     TopicType     `json:"topic"`
        Payload   hexutil.Bytes `json:"payload"`
        Padding   hexutil.Bytes `json:"padding"`
        PoW       float64       `json:"pow"`
        Hash      hexutil.Bytes `json:"hash"`
        Dst       hexutil.Bytes `json:"recipientPublicKey,omitempty"`
    }
    var enc Message
    enc.Sig = m.Sig
    enc.TTL = m.TTL
    enc.Timestamp = m.Timestamp
    enc.Topic = m.Topic
    enc.Payload = m.Payload
    enc.Padding = m.Padding
    enc.PoW = m.PoW
    enc.Hash = m.Hash
    enc.Dst = m.Dst
    return json.Marshal(&enc)
}

func (m *Message) UnmarshalJSON(input []byte) error {
    type Message struct {
        Sig       hexutil.Bytes `json:"sig,omitempty"`
        TTL       *uint32       `json:"ttl"`
        Timestamp *uint32       `json:"timestamp"`
        Topic     *TopicType    `json:"topic"`
        Payload   hexutil.Bytes `json:"payload"`
        Padding   hexutil.Bytes `json:"padding"`
        PoW       *float64      `json:"pow"`
        Hash      hexutil.Bytes `json:"hash"`
        Dst       hexutil.Bytes `json:"recipientPublicKey,omitempty"`
    }
    var dec Message
    if err := json.Unmarshal(input, &dec); err != nil {
        return err
    }
    if dec.Sig != nil {
        m.Sig = dec.Sig
    }
    if dec.TTL != nil {
        m.TTL = *dec.TTL
    }
    if dec.Timestamp != nil {
        m.Timestamp = *dec.Timestamp
    }
    if dec.Topic != nil {
        m.Topic = *dec.Topic
    }
    if dec.Payload != nil {
        m.Payload = dec.Payload
    }
    if dec.Padding != nil {
        m.Padding = dec.Padding
    }
    if dec.PoW != nil {
        m.PoW = *dec.PoW
    }
    if dec.Hash != nil {
        m.Hash = dec.Hash
    }
    if dec.Dst != nil {
        m.Dst = dec.Dst
    }
    return nil
}