mirror of
https://github.com/logos-messaging/logos-messaging-go-bindings.git
synced 2026-01-05 15:33:08 +00:00
defining envelope type instead of interface
This commit is contained in:
parent
faa231851e
commit
60fb873106
@ -9,13 +9,7 @@ import (
|
||||
// Envelope contains information about the pubsub topic of a WakuMessage
|
||||
// and a hash used to identify a message based on the bytes of a WakuMessage
|
||||
// protobuffer
|
||||
type Envelope interface {
|
||||
Message() *pb.WakuMessage
|
||||
PubsubTopic() string
|
||||
Hash() MessageHash
|
||||
}
|
||||
|
||||
type envelopeImpl struct {
|
||||
type Envelope struct {
|
||||
msg *pb.WakuMessage
|
||||
topic string
|
||||
hash MessageHash
|
||||
@ -38,18 +32,14 @@ type tmpEnvelopeStruct struct {
|
||||
}
|
||||
|
||||
// NewEnvelope creates a new Envelope from a json string generated in nwaku
|
||||
func NewEnvelope(jsonEventStr string) (Envelope, error) {
|
||||
func NewEnvelope(jsonEventStr string) (*Envelope, error) {
|
||||
tmpEnvelopeStruct := tmpEnvelopeStruct{}
|
||||
err := json.Unmarshal([]byte(jsonEventStr), &tmpEnvelopeStruct)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &envelopeImpl{
|
||||
return &Envelope{
|
||||
msg: &pb.WakuMessage{
|
||||
Payload: tmpEnvelopeStruct.WakuMessage.Payload,
|
||||
ContentTopic: tmpEnvelopeStruct.WakuMessage.ContentTopic,
|
||||
@ -64,14 +54,14 @@ func NewEnvelope(jsonEventStr string) (Envelope, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (e *envelopeImpl) Message() *pb.WakuMessage {
|
||||
func (e *Envelope) Message() *pb.WakuMessage {
|
||||
return e.msg
|
||||
}
|
||||
|
||||
func (e *envelopeImpl) PubsubTopic() string {
|
||||
func (e *Envelope) PubsubTopic() string {
|
||||
return e.topic
|
||||
}
|
||||
|
||||
func (e *envelopeImpl) Hash() MessageHash {
|
||||
func (e *Envelope) Hash() MessageHash {
|
||||
return e.hash
|
||||
}
|
||||
|
||||
@ -484,7 +484,7 @@ func (n *WakuNode) parseMessageEvent(eventStr string) {
|
||||
if err != nil {
|
||||
Error("could not parse message %v", err)
|
||||
}
|
||||
n.MsgChan <- envelope
|
||||
n.MsgChan <- *envelope
|
||||
}
|
||||
|
||||
func (n *WakuNode) parseTopicHealthChangeEvent(eventStr string) {
|
||||
|
||||
@ -155,10 +155,6 @@ func (n *WakuNode) VerifyMessageReceived(expectedMessage *pb.WakuMessage, expect
|
||||
|
||||
select {
|
||||
case envelope := <-n.MsgChan:
|
||||
if envelope == nil {
|
||||
Error("Received envelope is nil on node %s", n.nodeName)
|
||||
return errors.New("received envelope is nil")
|
||||
}
|
||||
if string(expectedMessage.Payload) != string(envelope.Message().Payload) {
|
||||
Error("Payload does not match on node %s", n.nodeName)
|
||||
return errors.New("payload does not match")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user