mirror of
https://github.com/logos-messaging/logos-messaging-go-bindings.git
synced 2026-01-02 14:03:10 +00:00
chore: overriding json unmarshaler (#73)
This commit is contained in:
parent
b95c71a08b
commit
e37fbd26d6
@ -31,27 +31,27 @@ type wakuEnvelope struct {
|
||||
MessageHash MessageHash `json:"messageHash"`
|
||||
}
|
||||
|
||||
// NewEnvelope creates a new Envelope from a json string generated in nwaku
|
||||
func NewEnvelope(jsonEventStr string) (*Envelope, error) {
|
||||
// UnmarshalJSON implements the json.Unmarshaler interface
|
||||
func (e *Envelope) UnmarshalJSON(input []byte) error {
|
||||
wakuEnvelope := wakuEnvelope{}
|
||||
err := json.Unmarshal([]byte(jsonEventStr), &wakuEnvelope)
|
||||
err := json.Unmarshal(input, &wakuEnvelope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
return &Envelope{
|
||||
msg: &pb.WakuMessage{
|
||||
Payload: wakuEnvelope.WakuMessage.Payload,
|
||||
ContentTopic: wakuEnvelope.WakuMessage.ContentTopic,
|
||||
Version: wakuEnvelope.WakuMessage.Version,
|
||||
Timestamp: wakuEnvelope.WakuMessage.Timestamp,
|
||||
Meta: wakuEnvelope.WakuMessage.Meta,
|
||||
Ephemeral: wakuEnvelope.WakuMessage.Ephemeral,
|
||||
RateLimitProof: wakuEnvelope.WakuMessage.RateLimitProof,
|
||||
},
|
||||
topic: wakuEnvelope.PubsubTopic,
|
||||
hash: wakuEnvelope.MessageHash,
|
||||
}, nil
|
||||
e.msg = &pb.WakuMessage{
|
||||
Payload: wakuEnvelope.WakuMessage.Payload,
|
||||
ContentTopic: wakuEnvelope.WakuMessage.ContentTopic,
|
||||
Version: wakuEnvelope.WakuMessage.Version,
|
||||
Timestamp: wakuEnvelope.WakuMessage.Timestamp,
|
||||
Meta: wakuEnvelope.WakuMessage.Meta,
|
||||
Ephemeral: wakuEnvelope.WakuMessage.Ephemeral,
|
||||
RateLimitProof: wakuEnvelope.WakuMessage.RateLimitProof,
|
||||
}
|
||||
e.topic = wakuEnvelope.PubsubTopic
|
||||
e.hash = wakuEnvelope.MessageHash
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Envelope) Message() *pb.WakuMessage {
|
||||
|
||||
@ -480,12 +480,14 @@ func (n *WakuNode) OnEvent(eventStr string) {
|
||||
}
|
||||
|
||||
func (n *WakuNode) parseMessageEvent(eventStr string) {
|
||||
envelope, err := common.NewEnvelope(eventStr)
|
||||
var envelope common.Envelope
|
||||
err := json.Unmarshal([]byte(eventStr), &envelope)
|
||||
if err != nil {
|
||||
Error("could not parse message %v", err)
|
||||
return
|
||||
}
|
||||
select {
|
||||
case n.MsgChan <- *envelope:
|
||||
case n.MsgChan <- envelope:
|
||||
default:
|
||||
Warn("Can't deliver message to subscription, MsgChan is full")
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user