Skip to content

Commit 54438c2

Browse files
committed
Reorder files, add comments, init module
1 parent 1fb2b47 commit 54438c2

File tree

8 files changed

+25
-8
lines changed

8 files changed

+25
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ _testmain.go
2222
*.exe
2323
*.test
2424
*.prof
25+
26+
# Development environment
27+
.envrc

cayennelpp/decoder.go renamed to decoder.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017 The Things Network
1+
// Copyright © 2021 The Things Network
22
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
33

44
package cayennelpp
@@ -9,8 +9,10 @@ import (
99
"io"
1010
)
1111

12-
var ErrInvalidChannel = errors.New("cayennelpp: unknown type")
12+
// ErrInvalidChannelType indicates that the channel type is invalid.
13+
var ErrInvalidChannelType = errors.New("cayennelpp: unknown type")
1314

15+
// UplinkTarget represents a target that processes decoded uplink values.
1416
type UplinkTarget interface {
1517
DigitalInput(channel, value uint8)
1618
DigitalOutput(channel, value uint8)
@@ -26,10 +28,12 @@ type UplinkTarget interface {
2628
GPS(channel uint8, latitude, longitude, altitude float32)
2729
}
2830

31+
// DownlinkTarget represents a target that processes decoded downlink values.
2932
type DownlinkTarget interface {
3033
Port(channel uint8, value float32)
3134
}
3235

36+
// Decoder decodes CayenneLPP encoded values.
3337
type Decoder interface {
3438
DecodeUplink(target UplinkTarget) error
3539
DecodeDownlink(target DownlinkTarget) error
@@ -39,6 +43,7 @@ type decoder struct {
3943
r io.Reader
4044
}
4145

46+
// NewDecoder instantiates a CayenneLPP decoder.
4247
func NewDecoder(r io.Reader) Decoder {
4348
return &decoder{r}
4449
}
@@ -79,7 +84,7 @@ func (d *decoder) DecodeUplink(target UplinkTarget) error {
7984
case GPS:
8085
err = d.decodeGPS(buf[0], target)
8186
default:
82-
err = ErrInvalidChannel
87+
err = ErrInvalidChannelType
8388
}
8489
if err != nil {
8590
return err

cayennelpp/decoder_test.go renamed to decoder_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017 The Things Network
1+
// Copyright © 2021 The Things Network
22
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
33

44
package cayennelpp
@@ -131,7 +131,7 @@ func TestDecode(t *testing.T) {
131131
target := &target{make(map[uint8]interface{})}
132132

133133
err := decoder.DecodeUplink(target)
134-
a.So(err, ShouldEqual, ErrInvalidChannel)
134+
a.So(err, ShouldEqual, ErrInvalidChannelType)
135135
}
136136

137137
// Not enough data: uplink

cayennelpp/encoder.go renamed to encoder.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017 The Things Network
1+
// Copyright © 2021 The Things Network
22
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
33

44
package cayennelpp
@@ -9,6 +9,7 @@ import (
99
"io"
1010
)
1111

12+
// Encoder encodes values to CayenneLPP.
1213
type Encoder interface {
1314
Grow(n int)
1415
Bytes() []byte
@@ -33,6 +34,7 @@ type encoder struct {
3334
buf *bytes.Buffer
3435
}
3536

37+
// NewEncoder instantiates an CayenneLPP encoder.
3638
func NewEncoder() Encoder {
3739
return &encoder{
3840
buf: new(bytes.Buffer),

cayennelpp/encoder_test.go renamed to encoder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017 The Things Network
1+
// Copyright © 2021 The Things Network
22
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
33

44
package cayennelpp

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/TheThingsNetwork/go-cayenne-lib
2+
3+
go 1.15
4+
5+
require github.com/smartystreets/assertions v1.2.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
2+
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=

cayennelpp/types.go renamed to types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017 The Things Network
1+
// Copyright © 2021 The Things Network
22
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
33

44
package cayennelpp

0 commit comments

Comments
 (0)