go-waku/waku/v2/protocol/pb/validation.go
Prem Chaitanya Prathi d7249fc123
fix: rest api errors (#919)
Co-authored-by: richΛrd <info@richardramos.me>
2023-11-24 10:26:06 +05:30

30 lines
527 B
Go

package pb
import (
"errors"
)
const MaxMetaAttrLength = 64
var (
ErrMissingPayload = errors.New("missing Payload field")
ErrMissingContentTopic = errors.New("missing ContentTopic field")
ErrInvalidMetaLength = errors.New("invalid length for Meta field")
)
func (msg *WakuMessage) Validate() error {
if len(msg.Payload) == 0 {
return ErrMissingPayload
}
if msg.ContentTopic == "" {
return ErrMissingContentTopic
}
if len(msg.Meta) > MaxMetaAttrLength {
return ErrInvalidMetaLength
}
return nil
}