mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-26 13:48:53 +08:00
NOISSUE - Fix lora-adapter Object decode (#610)
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
parent
fa7d638453
commit
a60a5c1ba1
@ -40,5 +40,5 @@ type Message struct {
|
||||
FCnt int `json:"fCnt"`
|
||||
FPort int `json:"fPort"`
|
||||
Data string `json:"data"`
|
||||
Object string `json:"object"`
|
||||
Object interface{} `json:"object"`
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package lora
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/mainflux/mainflux"
|
||||
@ -88,13 +89,17 @@ func (as *adapterService) Publish(m Message) error {
|
||||
// field Object isn't empty. Otherwise, decode standard field Data.
|
||||
var payload []byte
|
||||
switch m.Object {
|
||||
case "":
|
||||
case nil:
|
||||
payload, err = base64.StdEncoding.DecodeString(m.Data)
|
||||
if err != nil {
|
||||
return ErrMalformedMessage
|
||||
}
|
||||
default:
|
||||
payload = []byte(m.Object)
|
||||
jo, err := json.Marshal(m.Object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
payload = []byte(jo)
|
||||
}
|
||||
|
||||
// Publish on Mainflux NATS broker
|
||||
|
Loading…
x
Reference in New Issue
Block a user