func (x TxAcknowledgment_Result) MarshalProtoJSON(s *jsonplugin.MarshalState) {
	s.WriteEnumString(int32(x), TxAcknowledgment_Result_name)
}
MarshalProtoJSON marshals the TxAcknowledgment_Result to JSON.
package ttnpb
import (
	gogo "github.com/TheThingsIndustries/protoc-gen-go-json/gogo"
	jsonplugin "github.com/TheThingsIndustries/protoc-gen-go-json/jsonplugin"
)
func (x PayloadFormatter) MarshalProtoJSON(s *jsonplugin.MarshalState) {
	s.WriteEnumString(int32(x), PayloadFormatter_name)
}
var PayloadFormatter_customvalue = map[string]int32{
	"NONE":         0,
	"REPOSITORY":   1,
	"GRPC_SERVICE": 2,
	"JAVASCRIPT":   3,
	"CAYENNELPP":   4,
}
func (x *PayloadFormatter) UnmarshalProtoJSON(s *jsonplugin.UnmarshalState) {
	v := s.ReadEnum(PayloadFormatter_value, PayloadFormatter_customvalue)
	if err := s.Err(); err != nil {
		s.SetErrorf("could not read PayloadFormatter enum: %v", err)
		return
	}
	*x = PayloadFormatter(v)
}
func (x *UplinkMessage) MarshalProtoJSON(s *jsonplugin.MarshalState) {
	if x == nil {
		s.WriteNil()
		return
	}
	s.WriteObjectStart()
	var wroteField bool
	if len(x.RawPayload) > 0 || s.HasField("raw_payload") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("raw_payload")
		s.WriteBytes(x.RawPayload)
	}
	if x.Payload != nil || s.HasField("payload") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("payload")
		x.Payload.MarshalProtoJSON(s.WithField("payload"))
	}
	if true {  
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("settings")
		x.Settings.MarshalProtoJSON(s.WithField("settings"))
	}
	if len(x.RxMetadata) > 0 || s.HasField("rx_metadata") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("rx_metadata")
		s.WriteArrayStart()
		var wroteElement bool
		for _, element := range x.RxMetadata {
			s.WriteMoreIf(&wroteElement)
			element.MarshalProtoJSON(s.WithField("rx_metadata"))
		}
		s.WriteArrayEnd()
	}
	if true {  
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("received_at")
		s.WriteTime(x.ReceivedAt)
	}
	if len(x.CorrelationIds) > 0 || s.HasField("correlation_ids") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("correlation_ids")
		s.WriteStringArray(x.CorrelationIds)
	}
	if x.DeviceChannelIndex != 0 || s.HasField("device_channel_index") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("device_channel_index")
		s.WriteUint32(x.DeviceChannelIndex)
	}
	if x.ConsumedAirtime != nil || s.HasField("consumed_airtime") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("consumed_airtime")
		if x.ConsumedAirtime == nil {
			s.WriteNil()
		} else {
			s.WriteDuration(*x.ConsumedAirtime)
		}
	}
	s.WriteObjectEnd()
}
func (x *UplinkMessage) UnmarshalProtoJSON(s *jsonplugin.UnmarshalState) {
	if s.ReadNil() {
		return
	}
	s.ReadObject(func(key string) {
		switch key {
		default:
			s.ReadAny()  
		case "raw_payload", "rawPayload":
			s.AddField("raw_payload")
			x.RawPayload = s.ReadBytes()
		case "payload":
			if !s.ReadNil() {
				x.Payload = &Message{}
				x.Payload.UnmarshalProtoJSON(s.WithField("payload", true))
			}
		case "settings":
			if !s.ReadNil() {
				x.Settings.UnmarshalProtoJSON(s.WithField("settings", true))
			}
		case "rx_metadata", "rxMetadata":
			s.AddField("rx_metadata")
			s.ReadArray(func() {
				if s.ReadNil() {
					x.RxMetadata = append(x.RxMetadata, nil)
					return
				}
				v := &RxMetadata{}
				v.UnmarshalProtoJSON(s.WithField("rx_metadata", false))
				if s.Err() != nil {
					return
				}
				x.RxMetadata = append(x.RxMetadata, v)
			})
		case "received_at", "receivedAt":
			s.AddField("received_at")
			v := s.ReadTime()
			if s.Err() != nil {
				return
			}
			x.ReceivedAt = *v
		case "correlation_ids", "correlationIds":
			s.AddField("correlation_ids")
			x.CorrelationIds = s.ReadStringArray()
		case "device_channel_index", "deviceChannelIndex":
			s.AddField("device_channel_index")
			x.DeviceChannelIndex = s.ReadUint32()
		case "consumed_airtime", "consumedAirtime":
			s.AddField("consumed_airtime")
			v := s.ReadDuration()
			if s.Err() != nil {
				return
			}
			x.ConsumedAirtime = v
		}
	})
}
func (x *DownlinkMessage) MarshalProtoJSON(s *jsonplugin.MarshalState) {
	if x == nil {
		s.WriteNil()
		return
	}
	s.WriteObjectStart()
	var wroteField bool
	if len(x.RawPayload) > 0 || s.HasField("raw_payload") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("raw_payload")
		s.WriteBytes(x.RawPayload)
	}
	if x.Payload != nil || s.HasField("payload") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("payload")
		x.Payload.MarshalProtoJSON(s.WithField("payload"))
	}
	if x.EndDeviceIds != nil || s.HasField("end_device_ids") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("end_device_ids")
		gogo.MarshalMessage(s, x.EndDeviceIds)
	}
	if x.Settings != nil {
		switch ov := x.Settings.(type) {
		case *DownlinkMessage_Request:
			s.WriteMoreIf(&wroteField)
			s.WriteObjectField("request")
			ov.Request.MarshalProtoJSON(s.WithField("request"))
		case *DownlinkMessage_Scheduled:
			s.WriteMoreIf(&wroteField)
			s.WriteObjectField("scheduled")
			ov.Scheduled.MarshalProtoJSON(s.WithField("scheduled"))
		}
	}
	if len(x.CorrelationIds) > 0 || s.HasField("correlation_ids") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("correlation_ids")
		s.WriteStringArray(x.CorrelationIds)
	}
	if len(x.SessionKeyId) > 0 || s.HasField("session_key_id") {
		s.WriteMoreIf(&wroteField)
		s.WriteObjectField("session_key_id")
		s.WriteBytes(x.SessionKeyId)
	}
	s.WriteObjectEnd()
}
func (x *DownlinkMessage) UnmarshalProtoJSON(s *jsonplugin.UnmarshalState) {
	if s.ReadNil() {
		return
	}
	s.ReadObject(func(key string) {
		switch key {
		default:
			s.ReadAny()  
		case "raw_payload", "rawPayload":
			s.AddField("raw_payload")
			x.RawPayload = s.ReadBytes()
		case "payload":
			if !s.ReadNil() {
				x.Payload = &Message{}
				x.Payload.UnmarshalProtoJSON(s.WithField("payload", true))
			}
		case "end_device_ids", "endDeviceIds":
			s.AddField("end_device_ids")
			var v EndDeviceIdentifiers
			gogo.UnmarshalMessage(s, &v)
			x.EndDeviceIds = &v
		case "request":
			ov := &DownlinkMessage_Request{}
			if !s.ReadNil() {
				ov.Request = &TxRequest{}
				ov.Request.UnmarshalProtoJSON(s.WithField("request", true))
			}
			x.Settings = ov
		case "scheduled":
			ov := &DownlinkMessage_Scheduled{}
			if !s.ReadNil() {
				ov.Scheduled = &TxSettings{}
				ov.Scheduled.UnmarshalProtoJSON(s.WithField("scheduled", true))
			}
			x.Settings = ov
		case "correlation_ids", "correlationIds":
			s.AddField("correlation_ids")
			x.CorrelationIds = s.ReadStringArray()
		case "session_key_id", "sessionKeyId":
			s.AddField("session_key_id")
			x.SessionKeyId = s.ReadBytes()
		}
	})
}