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

Function FromProto

pkg/events/events.go:232–269  ·  view source on GitHub ↗

FromProto returns the event from its protobuf representation.

(pb *ttnpb.Event)

Source from the content-addressed store, hash-verified

230
231// FromProto returns the event from its protobuf representation.
232func 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.
272func UnmarshalJSON(data []byte) (Event, error) {

Callers 6

subscribeTaskMethod · 0.92
subscribeTaskMethod · 0.92
FetchHistoryMethod · 0.92
SubscribeWithHistoryMethod · 0.92
FindRelatedMethod · 0.92
UnmarshalJSONMethod · 0.85

Calls 2

InterfaceFunction · 0.92
unmarshalContextFunction · 0.85

Tested by

no test coverage detected