MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / ValidateFields

Method ValidateFields

pkg/ttnpb/lorawan.pb.validate.go:38–167  ·  view source on GitHub ↗

ValidateFields checks the field values on Message with the rules defined in the proto definition for this message. If any rules are violated, an error is returned.

(paths ...string)

Source from the content-addressed store, hash-verified

36// the proto definition for this message. If any rules are violated, an error
37// is returned.
38func (m *Message) ValidateFields(paths ...string) error {
39 if m == nil {
40 return nil
41 }
42
43 if len(paths) == 0 {
44 paths = MessageFieldPathsNested
45 }
46
47 for name, subs := range _processPaths(append(paths[:0:0], paths...)) {
48 _ = subs
49 switch name {
50 case "m_hdr":
51
52 if m.GetMHdr() == nil {
53 return MessageValidationError{
54 field: "m_hdr",
55 reason: "value is required",
56 }
57 }
58
59 if v, ok := interface{}(m.GetMHdr()).(interface{ ValidateFields(...string) error }); ok {
60 if err := v.ValidateFields(subs...); err != nil {
61 return MessageValidationError{
62 field: "m_hdr",
63 reason: "embedded message failed validation",
64 cause: err,
65 }
66 }
67 }
68
69 case "mic":
70
71 if l := len(m.GetMic()); l < 0 || l > 4 {
72 return MessageValidationError{
73 field: "mic",
74 reason: "value length must be between 0 and 4 bytes, inclusive",
75 }
76 }
77
78 case "Payload":
79 if m.Payload == nil {
80 return MessageValidationError{
81 field: "Payload",
82 reason: "value is required",
83 }
84 }
85 if len(subs) == 0 {
86 subs = []string{
87 "mac_payload", "join_request_payload", "join_accept_payload", "rejoin_request_payload",
88 }
89 }
90 for name, subs := range _processPaths(subs) {
91 _ = subs
92 switch name {
93 case "mac_payload":
94 w, ok := m.Payload.(*Message_MacPayload)
95 if !ok || w == nil {

Callers

nothing calls this directly

Calls 8

GetMHdrMethod · 0.95
GetMicMethod · 0.95
GetMacPayloadMethod · 0.95
GetJoinRequestPayloadMethod · 0.95
GetJoinAcceptPayloadMethod · 0.95
_processPathsFunction · 0.85
ValidateFieldsMethod · 0.45

Tested by

no test coverage detected