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

Method SetFunc

pkg/networkserver/device_state.go:273–290  ·  view source on GitHub ↗

SetFunc is the function meant to be passed to SetByID.

(f func(context.Context, *ttnpb.EndDevice) error)

Source from the content-addressed store, hash-verified

271
272// SetFunc is the function meant to be passed to SetByID.
273func (st *setDeviceState) SetFunc(f func(context.Context, *ttnpb.EndDevice) error) func(context.Context, *ttnpb.EndDevice) (*ttnpb.EndDevice, []string, error) { // nolint: lll
274 return func(ctx context.Context, stored *ttnpb.EndDevice) (*ttnpb.EndDevice, []string, error) {
275 for p, shouldBeZero := range st.zeroPaths {
276 if stored.FieldIsZero(p) != shouldBeZero {
277 return nil, nil, newInvalidFieldValueError(p)
278 }
279 }
280 for _, g := range st.onGet {
281 if err := g(stored); err != nil {
282 return nil, nil, err
283 }
284 }
285 if err := f(ctx, stored); err != nil {
286 return nil, nil, err
287 }
288 return st.Device, st.SetFields(), nil
289 }
290}
291
292func newSetDeviceState(dev *ttnpb.EndDevice, paths ...string) *setDeviceState {
293 return &setDeviceState{

Callers 11

SetMethod · 0.80
SetMethod · 0.80
TestDeviceRegistryDeleteFunction · 0.80
SetMethod · 0.80
SetMethod · 0.80
TestDeviceRegistrySetFunction · 0.80
TestDeviceRegistryDeleteFunction · 0.80

Calls 3

SetFieldsMethod · 0.95
FieldIsZeroMethod · 0.45

Tested by 10

SetMethod · 0.64
TestDeviceRegistryDeleteFunction · 0.64
SetMethod · 0.64
SetMethod · 0.64
TestDeviceRegistrySetFunction · 0.64
TestDeviceRegistryDeleteFunction · 0.64