2023-11-10 18:31:36 +00:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/waku-org/go-waku/cmd/waku/server"
|
|
|
|
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RestWakuMessage struct {
|
|
|
|
Payload server.Base64URLByte `json:"payload"`
|
|
|
|
ContentTopic string `json:"contentTopic"`
|
|
|
|
Version *uint32 `json:"version,omitempty"`
|
|
|
|
Timestamp *int64 `json:"timestamp,omitempty"`
|
|
|
|
Meta []byte `json:"meta,omitempty"`
|
2024-03-26 06:15:59 +00:00
|
|
|
Ephemeral *bool `json:"ephemeral"`
|
2023-11-10 18:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RestWakuMessage) FromProto(input *pb.WakuMessage) error {
|
|
|
|
if err := input.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
r.Payload = input.Payload
|
|
|
|
r.ContentTopic = input.ContentTopic
|
|
|
|
r.Timestamp = input.Timestamp
|
|
|
|
r.Version = input.Version
|
|
|
|
r.Meta = input.Meta
|
2024-03-26 06:15:59 +00:00
|
|
|
r.Ephemeral = input.Ephemeral
|
2023-11-10 18:31:36 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RestWakuMessage) ToProto() (*pb.WakuMessage, error) {
|
|
|
|
if r == nil {
|
|
|
|
return nil, errors.New("wakumessage is missing")
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := &pb.WakuMessage{
|
|
|
|
Payload: r.Payload,
|
|
|
|
ContentTopic: r.ContentTopic,
|
|
|
|
Version: r.Version,
|
|
|
|
Timestamp: r.Timestamp,
|
|
|
|
Meta: r.Meta,
|
2024-03-26 06:15:59 +00:00
|
|
|
Ephemeral: r.Ephemeral,
|
2023-11-10 18:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return msg, nil
|
|
|
|
}
|