// PublishUplinkFields publishes uplink fields to MQTT
168381
func (c *DefaultClient) PublishUplinkFields(appID string, devID string, fields map[string]interface{}) Token {
	flattenedFields := make(map[string]interface{})
	flatten("", "/", fields, flattenedFields)
	tokens := make([]Token, 0, len(flattenedFields))
	for field, value := range flattenedFields {
		topic := DeviceTopic{appID, devID, DeviceUplink, field}
		pld, _ := json.Marshal(value)
		token := c.publish(topic.String(), pld)
		tokens = append(tokens, token)
	}
	t := newToken()
	go func() {
		for _, token := range tokens {
			token.Wait()
			if token.Error() != nil {
				c.ctx.Warnf("mqtt: error publishing uplink fields: %s", token.Error())
				t.err = token.Error()
			}
		}
		t.flowComplete()
	}()
	return t
}
77701
func (p PHYPayload) ValidateUplinkJoinMIC(key AES128Key) (bool, error) {
	mic, err := p.calculateUplinkJoinMIC(key)
	if err != nil {
		return false, err
	}
	return p.MIC == mic, nil
}
1229959
func (n *Nats) PublishRequest(subject string, reply string, data PayloadWithContext) error {
	n.updateContext(data, RequestType_PUBREQ, nil)
	return n.EncCon.PublishRequest(subject, reply, data)
}
240958
func (h *handler) ConvertFieldsUp(ctx ttnlog.Interface, _ *pb_broker.DeduplicatedUplinkMessage, appUp *types.UplinkMessage, dev *device.Device) error {
	// Find Application
	app, err := h.applications.Get(appUp.AppID)
	if err != nil {
		return nil // Do not process if application not found
	}

	var decoder PayloadDecoder
	switch app.PayloadFormat {
	case application.PayloadFormatCustom:
		decoder = &CustomUplinkFunctions{
			Decoder:   app.CustomDecoder,
			Converter: app.CustomConverter,
			Validator: app.CustomValidator,
			Logger:    functions.Ignore,
		}
	case application.PayloadFormatCayenneLPP:
		decoder = &cayennelpp.Decoder{}
	default:
		return nil
	}

	fields, valid, err := decoder.Decode(appUp.PayloadRaw, appUp.FPort)
	if err != nil {
		// Emit the error
		h.qEvent <- &types.DeviceEvent{
			AppID: appUp.AppID,
			DevID: appUp.DevID,
			Event: types.UplinkErrorEvent,
			Data:  types.ErrorEventData{Error: fmt.Sprintf("Unable to decode payload fields: %s", err)},
		}

		// Do not set fields if processing failed, but allow the handler to continue processing
		// without payload formatting
		return nil
	}

	if !valid {
		return errors.NewErrInvalidArgument("Payload", "payload validator function returned false")
	}

	// Check if the functions return valid JSON
	_, err = json.Marshal(fields)
	if err != nil {
		// Emit the error
		h.qEvent <- &types.DeviceEvent{
			AppID: appUp.AppID,
			DevID: appUp.DevID,
			Event: types.UplinkErrorEvent,
			Data:  types.ErrorEventData{Error: fmt.Sprintf("Payload Function output cannot be marshaled to JSON: %s", err.Error())},
		}

		// Do not set fields if processing failed, but allow the handler to continue processing
		// without payload formatting
		return nil
	}

	appUp.PayloadFields = fields
	appUp.Attributes = dev.Attributes

	return nil
}
671370
func (b *pubsubBroker) Publish(topic string, msg *broker.Message, opts ...broker.PublishOption) error {
	t := b.client.Topic(topic)
	ctx := context.Background()

	exists, err := t.Exists(ctx)
	if err != nil {
		return err
	}

	if !exists {
		tt, err := b.client.CreateTopic(ctx, topic)
		if err != nil {
			return err
		}
		t = tt
	}

	m := &pubsub.Message{
		ID:         "m-" + uuid.New().String(),
		Data:       msg.Body,
		Attributes: msg.Header,
	}

	pr := t.Publish(ctx, m)
	_, err = pr.Get(ctx)
	return err
}
1296132
func (w *clientWrapper) Publish(ctx context.Context, p client.Message, opts ...client.PublishOption) (err error) {
	t := newPublicationTracker(p, ClientProfile)
	ctx = t.start(ctx, true)

	defer func() { t.end(ctx, err) }()

	ctx = injectTraceIntoCtx(ctx, t.span)

	err = w.Client.Publish(ctx, p, opts...)
	return
}
922345
func setPublishOption(k, v interface{}) broker.PublishOption {
	return func(o *broker.PublishOptions) {
		if o.Context == nil {
			o.Context = context.Background()
		}
		o.Context = context.WithValue(o.Context, k, v)
	}
}
508633
func (o *VLANTemplate) UplinkConnections(info *bambou.FetchingInfo) (UplinkConnectionsList, *bambou.Error) {

	var list UplinkConnectionsList
	err := bambou.CurrentSession().FetchChildren(o, UplinkConnectionIdentity, &list, info)
	return list, err
}
901703
func (s *SkillsStoreSkill) SetSupportsLinking(v bool) *SkillsStoreSkill {
	s.SupportsLinking = &v
	return s
}
905044
func eventUpdatedFields(dev *device.Device) types.DeviceEventData {
	changeList := dev.ChangedFields()
	e := types.DeviceEventData{}
	for _, key := range changeList {
		switch key {
		case "Latitude":
			e.Latitude = dev.Latitude
		case "Longitude":
			e.Longitude = dev.Longitude
		case "Altitude":
			e.Altitude = dev.Altitude
		case "UpdatedAt":
			e.UpdatedAt = dev.UpdatedAt
		}
	}
	return e
}
1001571
func (conn *ProtoManualConnection) NewSyncPublisherToPartition(topic string, partition int32) (messaging.ProtoPublisher, error) {
	return &protoManualSyncPublisherKafka{conn, topic, partition}, nil
}
383490
func (w *DeploymentStream) Publish(status twelvefactor.Status) error {
	return w.Status(status.Message)
}
348458
func (b *EventBus) PublishEvent(ctx context.Context, event eh.Event) error {
	b.group.publish(ctx, event)
	return nil
}
983397
func (d *Driver) PublishEvent(name string, data string) {
	d.Publish(d.Event(name), data)
}
485713
func NewUplinkConnection() *UplinkConnection {

	return &UplinkConnection{
		PATEnabled:              true,
		AddressFamily:           "IPV4",
		UnderlayEnabled:         true,
		Inherited:               false,
		InstallerManaged:        false,
		InterfaceConnectionType: "AUTOMATIC",
		Mode:              "Dynamic",
		Role:              "PRIMARY",
		DownloadRateLimit: 8.0,
		AuxiliaryLink:     false,
	}
}
159920
func (r *ReadersAndUpdates) writeFieldUpdates(dir store.Directory,
	dvUpdates *DocValuesFieldUpdatesContainer) error {
	panic("not implemented yet")
}
721357
func (o *UplinkConnection) CustomProperties(info *bambou.FetchingInfo) (CustomPropertiesList, *bambou.Error) {

	var list CustomPropertiesList
	err := bambou.CurrentSession().FetchChildren(o, CustomPropertyIdentity, &list, info)
	return list, err
}