-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder.go
36 lines (31 loc) · 885 Bytes
/
encoder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
package cayennelpp
import (
pb_handler "github.com/TheThingsNetwork/api/handler"
protocol "github.com/TheThingsNetwork/go-cayenne-lib/cayennelpp"
)
// Encoder is a CayenneLPP PayloadEncoder
type Encoder struct {
}
// Encode encodes the fields to CayenneLPP
func (e *Encoder) Encode(fields map[string]interface{}, fPort uint8) ([]byte, bool, error) {
encoder := protocol.NewEncoder()
for name, value := range fields {
key, channel, err := parseName(name)
if err != nil {
continue
}
switch key {
case valueKey:
if val, ok := value.(float64); ok {
encoder.AddPort(channel, float32(val))
}
}
}
return encoder.Bytes(), true, nil
}
// Log returns the log
func (e *Encoder) Log() []*pb_handler.LogEntry {
return nil
}