2023-10-24 16:26:02 +00:00
|
|
|
package pb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
const MaxMetaAttrLength = 64
|
|
|
|
|
|
|
|
var (
|
2023-11-24 04:56:06 +00:00
|
|
|
ErrMissingPayload = errors.New("missing Payload field")
|
|
|
|
ErrMissingContentTopic = errors.New("missing ContentTopic field")
|
|
|
|
ErrInvalidMetaLength = errors.New("invalid length for Meta field")
|
2023-10-24 16:26:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (msg *WakuMessage) Validate() error {
|
|
|
|
if len(msg.Payload) == 0 {
|
2023-11-24 04:56:06 +00:00
|
|
|
return ErrMissingPayload
|
2023-10-24 16:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if msg.ContentTopic == "" {
|
2023-11-24 04:56:06 +00:00
|
|
|
return ErrMissingContentTopic
|
2023-10-24 16:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(msg.Meta) > MaxMetaAttrLength {
|
2023-11-24 04:56:06 +00:00
|
|
|
return ErrInvalidMetaLength
|
2023-10-24 16:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|