ToDeviceID returns the end device identifier of the specified unique ID.
(uid string)
| 71 | |
| 72 | // ToDeviceID returns the end device identifier of the specified unique ID. |
| 73 | func ToDeviceID(uid string) (id *ttnpb.EndDeviceIdentifiers, err error) { |
| 74 | id = &ttnpb.EndDeviceIdentifiers{} |
| 75 | before, after, ok := strings.Cut(uid, ".") |
| 76 | if !ok { |
| 77 | return nil, errFormat.WithAttributes("value", uid) |
| 78 | } |
| 79 | id.ApplicationIds = &ttnpb.ApplicationIdentifiers{ |
| 80 | ApplicationId: before, |
| 81 | } |
| 82 | id.DeviceId = after |
| 83 | if err := id.ValidateFields("device_id", "application_ids"); err != nil { |
| 84 | return nil, errUniqueIdentifier.WithCause(err).WithAttributes("uid", uid) |
| 85 | } |
| 86 | return id, nil |
| 87 | } |
| 88 | |
| 89 | // ToGatewayID returns the gateway identifier of the specified unique ID. |
| 90 | func ToGatewayID(uid string) (id *ttnpb.GatewayIdentifiers, err error) { |