2021-04-22 00:09:37 +00:00
|
|
|
package protocol
|
2021-03-30 14:13:33 +00:00
|
|
|
|
2021-04-22 00:09:37 +00:00
|
|
|
import "github.com/status-im/go-waku/waku/v2/protocol/pb"
|
2021-03-30 14:13:33 +00:00
|
|
|
|
|
|
|
type Envelope struct {
|
2021-04-28 15:11:32 +00:00
|
|
|
msg *pb.WakuMessage
|
|
|
|
pubsubTopic string
|
|
|
|
size int
|
|
|
|
hash []byte
|
2021-03-30 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 20:10:44 +00:00
|
|
|
func NewEnvelope(msg *pb.WakuMessage, pubSubTopic string) *Envelope {
|
|
|
|
data, _ := msg.Marshal()
|
2021-03-30 14:13:33 +00:00
|
|
|
return &Envelope{
|
2021-04-28 15:11:32 +00:00
|
|
|
msg: msg,
|
|
|
|
pubsubTopic: pubSubTopic,
|
2021-04-28 20:10:44 +00:00
|
|
|
size: len(data),
|
|
|
|
hash: pb.Hash(data),
|
2021-03-30 14:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-22 00:09:37 +00:00
|
|
|
func (e *Envelope) Message() *pb.WakuMessage {
|
2021-03-30 14:13:33 +00:00
|
|
|
return e.msg
|
|
|
|
}
|
|
|
|
|
2021-04-28 15:11:32 +00:00
|
|
|
func (e *Envelope) PubsubTopic() string {
|
|
|
|
return e.pubsubTopic
|
|
|
|
}
|
|
|
|
|
2021-04-11 23:43:59 +00:00
|
|
|
func (e *Envelope) Hash() []byte {
|
2021-03-30 14:13:33 +00:00
|
|
|
return e.hash
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Envelope) Size() int {
|
|
|
|
return e.size
|
|
|
|
}
|