From 07e3459cac27bc3eeb93f94439a0b767be0a38d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Bustarret?= Date: Fri, 11 Jan 2019 15:26:13 +0100 Subject: [PATCH] Rename Version to BaseVersion (#12) * rename Version to BaseVersion to be in sync with RFC * updated README for 1.0.0 --- README.md | 6 ++++-- record.go | 4 ++-- senml.go | 12 ++++++------ senml_test.go | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 85ed183..96113a1 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,14 @@ `go get github.com/objenious/senml` -## Status: beta (no breaking changes expected) +## Status: stable -This package implements the SenML format (Sensor Measurement Lists, formerly known as Sensor Markup Language), as defined in [RFC8428](https://tools.ietf.org/html/rfc8428) +This package implements the SenML format (Sensor Measurement Lists, formerly known as Sensor Markup Language), as defined in [RFC8428](https://tools.ietf.org/html/rfc8428). This package is used in production on the Objenious LoRaWAN platform, and is maintained. +> Warning: a breaking change was introduced in version 1.0.0, with the Record.Version being renamed to Record.BaseVersion. + ## Encoding/decoding Encoding to/from JSON and XML is managed by the standard library. diff --git a/record.go b/record.go index ee4650a..df7d3fa 100644 --- a/record.go +++ b/record.go @@ -10,7 +10,7 @@ type Record struct { BaseValue *float64 `json:"bv,omitempty" xml:"bv,attr,omitempty"` BaseSum *float64 `json:"bs,omitempty" xml:"bs,attr,omitempty"` - Version int `json:"bver,omitempty" xml:"bver,attr,omitempty"` + BaseVersion int `json:"bver,omitempty" xml:"bver,attr,omitempty"` Name string `json:"n,omitempty" xml:"n,attr,omitempty"` Unit Unit `json:"u,omitempty" xml:"u,attr,omitempty"` @@ -39,7 +39,7 @@ func (r *Record) Equals(r2 *Record) bool { if r.BaseUnit != r2.BaseUnit { return false } - if r.Version != r2.Version { + if r.BaseVersion != r2.BaseVersion { return false } if r.Name != r2.Name { diff --git a/senml.go b/senml.go index 464896d..efec6cd 100644 --- a/senml.go +++ b/senml.go @@ -38,8 +38,8 @@ func (p Pack) Normalize() Pack { if p[i].BaseTime != 0 { btime = p[i].BaseTime } - if p[i].Version != 0 { - bver = p[i].Version + if p[i].BaseVersion != 0 { + bver = p[i].BaseVersion } if p[i].BaseUnit != "" { bunit = p[i].BaseUnit @@ -54,10 +54,10 @@ func (p Pack) Normalize() Pack { bsum = *p[i].BaseSum } r := Record{ - Name: bname + p[i].Name, - Time: btime + p[i].Time, - Unit: bunit, - Version: bver, + Name: bname + p[i].Name, + Time: btime + p[i].Time, + Unit: bunit, + BaseVersion: bver, } if p[i].Unit != "" { r.Unit = p[i].Unit diff --git a/senml_test.go b/senml_test.go index 15e3b00..754c150 100644 --- a/senml_test.go +++ b/senml_test.go @@ -444,7 +444,7 @@ func TestXML(t *testing.T) { }, { src: Pack{ - {BaseName: "urn:dev:ow:10e2073a01080063", BaseTime: 1.276020076001e+09, BaseUnit: Ampere, Version: 5, Name: "voltage", Unit: Volt, Value: Float(120.1)}, + {BaseName: "urn:dev:ow:10e2073a01080063", BaseTime: 1.276020076001e+09, BaseUnit: Ampere, BaseVersion: 5, Name: "voltage", Unit: Volt, Value: Float(120.1)}, {Name: "current", Time: -5, Value: Float(1.2)}, {Name: "current", Time: -4, Value: Float(1.3)}, {Name: "current", Time: -3, Value: Float(1.4)},