FromProto returns the event from its protobuf representation.
(pb *ttnpb.Event)
| 230 | |
| 231 | // FromProto returns the event from its protobuf representation. |
| 232 | func FromProto(pb *ttnpb.Event) (Event, error) { |
| 233 | ctx, err := unmarshalContext(context.Background(), pb.Context) |
| 234 | if err != nil { |
| 235 | return nil, err |
| 236 | } |
| 237 | var data any |
| 238 | if pb.Data != nil { |
| 239 | anyMsg, err := pb.Data.UnmarshalNew() |
| 240 | if err != nil { |
| 241 | return nil, err |
| 242 | } |
| 243 | data = anyMsg |
| 244 | v, ok := anyMsg.(*structpb.Value) |
| 245 | if ok { |
| 246 | iface, err := goproto.Interface(v) |
| 247 | if err != nil { |
| 248 | return nil, err |
| 249 | } |
| 250 | data = iface |
| 251 | } |
| 252 | } |
| 253 | return &event{ |
| 254 | ctx: ctx, |
| 255 | data: data, |
| 256 | innerEvent: &ttnpb.Event{ |
| 257 | UniqueId: pb.UniqueId, |
| 258 | Name: pb.Name, |
| 259 | Time: pb.Time, |
| 260 | Identifiers: pb.Identifiers, |
| 261 | CorrelationIds: pb.CorrelationIds, |
| 262 | Origin: pb.Origin, |
| 263 | Visibility: pb.Visibility, |
| 264 | Authentication: pb.Authentication, |
| 265 | RemoteIp: pb.RemoteIp, |
| 266 | UserAgent: pb.UserAgent, |
| 267 | }, |
| 268 | }, nil |
| 269 | } |
| 270 | |
| 271 | // UnmarshalJSON unmarshals an event as JSON. |
| 272 | func UnmarshalJSON(data []byte) (Event, error) { |
no test coverage detected