Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AutoTime = true
AutoTime toggles the automatic setting of zero timestamps to now. Disabling this option results in timestamps relative to zero time when no exact time is given.
Functions ¶
func EncodeCBOR ¶
func EncodeCBOR(list []Measurement) (b []byte, err error)
EncodeCBOR encodes a list of measurements into CBOR.
func EncodeJSON ¶
func EncodeJSON(list []Measurement) ([]byte, error)
EncodeJSON encodes a list of measurements into JSON.
func EncodeXML ¶
func EncodeXML(list []Measurement) (b []byte, err error)
EncodeXML encodes a list of measurements into XML.
Types ¶
type Attributes ¶
Attributes contains the properties common to a measurement.
func (*Attributes) Attrs ¶
func (m *Attributes) Attrs() *Attributes
Attrs returns a pointer to the measurement of the Measurement value.
func (*Attributes) Equal ¶
func (m *Attributes) Equal(s *Attributes) bool
Equal returns true if the given attribute values are equal.
func (*Attributes) Object ¶
func (m *Attributes) Object() Object
Object returns a SenML object representing the value.
type Boolean ¶
type Boolean struct { Attributes Value bool }
Boolean represents a boolean measurement value. It implements Measurement.
func NewBoolean ¶
func NewBoolean(name string, value bool, unit Unit, time time.Time, updateTime time.Duration) *Boolean
NewBoolean returns a new Boolean value with the corresponding value and attributes.
func (*Boolean) Equal ¶
func (v *Boolean) Equal(ml Measurement) bool
Equal returns true if the given Measurement value is equal.
type Data ¶
type Data struct { Attributes Value []byte }
Data represents a measurement value returning binary data. It implements Measurement.
func (*Data) Equal ¶
func (v *Data) Equal(ml Measurement) bool
Equal returns true if the given Measurement value is equal.
type Measurement ¶
type Measurement interface { // Attrs returns a pointer to the measurement of the Measurement value. Attrs() *Attributes // Equal returns true if the given Measurement value is equal. Equal(Measurement) bool // Object returns a SenML object representing the value. Object() Object }
Measurement represents a single SenML measurement value. This interface is meant to represent the various Measurement values, see: Value, Sum, String, Boolean and Data.
func Decode ¶
func Decode(objects []Object) (list []Measurement, err error)
Decode decodes a list of Measurement objects into measurement values.
func DecodeCBOR ¶
func DecodeCBOR(c []byte) ([]Measurement, error)
DecodeCBOR decodes a list of measurements from CBOR.
func DecodeJSON ¶
func DecodeJSON(j []byte) ([]Measurement, error)
DecodeJSON decodes a list of measurements from JSON.
func DecodeXML ¶
func DecodeXML(x []byte) ([]Measurement, error)
DecodeXML decodes a list of measurements from XML.
type Object ¶
type Object struct { XMLName xml.Name `json:"-" xml:"senml" codec:"-"` BaseName string `json:"bn,omitempty" xml:"bn,attr,omitempty" codec:"-2"` BaseTime float64 `json:"bt,omitempty" xml:"bt,attr,omitempty" codec:"-3"` BaseUnit string `json:"bu,omitempty" xml:"bu,attr,omitempty" codec:"-4"` BaseValue float64 `json:"bv,omitempty" xml:"bv,attr,omitempty" codec:"-5"` BaseSum float64 `json:"bs,omitempty" xml:"bs,attr,omitempty" codec:"-6"` BaseVersion int `json:"bver,omitempty" xml:"bver,attr,omitempty" codec:"-1"` Name string `json:"n,omitempty" xml:"n,attr,omitempty" codec:"0"` Unit string `json:"u,omitempty" xml:"u,attr,omitempty" codec:"1"` Value *float64 `json:"v,omitempty" xml:"v,attr,omitempty" codec:"2"` StringValue string `json:"vs,omitempty" xml:"vs,attr,omitempty" codec:"3"` BooleanValue *bool `json:"vb,omitempty" xml:"vb,attr,omitempty" codec:"4"` DataValue []byte `json:"vd,omitempty" xml:"vd,attr,omitempty" codec:"8"` Sum *float64 `json:"s,omitempty" xml:"s,attr,omitempty" codec:"5"` Time float64 `json:"t,omitempty" xml:"t,attr,omitempty" codec:"6"` UpdateTime float64 `json:"ut,omitempty" xml:"ut,attr,omitempty" codec:"7"` // contains filtered or unexported fields }
Object represents a SenML object. This type is used as an intermediary between the Measurement values and the actual encoding. All SenML attributes are supported in this object.
func Encode ¶
func Encode(list []Measurement) (objects []Object)
Encode encodes a list of measurements to corresponding Measurement objects.
type String ¶
type String struct { Attributes Value string }
String represents a string measurement value. It implements Measurement.
func NewString ¶
func NewString(name string, value string, unit Unit, time time.Time, updateTime time.Duration) *String
NewString returns a new String value with the corresponding value and attributes.
func (*String) Equal ¶
func (v *String) Equal(ml Measurement) bool
Equal returns true if the given Measurement value is equal.
type Sum ¶
type Sum struct { Attributes Value float64 }
Sum represents an integrated floating point measurement value. It implements Measurement.
func (*Sum) Equal ¶
func (v *Sum) Equal(ml Measurement) bool
Equal returns true if the given Measurement value is equal.
type Unit ¶
type Unit string
Unit represents a SenML defined unit
const ( None Unit = "" Meter Unit = "m" Kilogram Unit = "kg" Gram Unit = "g" Second Unit = "s" Ampere Unit = "A" Kelvin Unit = "K" Candela Unit = "cd" Mole Unit = "mol" Hertz Unit = "Hz" Radian Unit = "rad" Steradian Unit = "sr" Newton Unit = "N" Pascal Unit = "Pa" Joule Unit = "J" Watt Unit = "W" Coulomb Unit = "C" Volt Unit = "V" Farad Unit = "F" Ohm Unit = "Ohm" Siemens Unit = "S" Weber Unit = "Wb" Tesla Unit = "T" Henry Unit = "H" Celsius Unit = "Cel" Lumen Unit = "lm" Lux Unit = "lx" Becquerel Unit = "Bq" Gray Unit = "Gy" Sievert Unit = "Sv" Katal Unit = "kat" SquareMeter Unit = "m2" CubicMeter Unit = "m3" Liter Unit = "l" MeterPerSecond Unit = "m/s" MeterPerSquareSecond Unit = "m/s2" CubicMeterPerSecond Unit = "m3/s" LiterPerSecond Unit = "l/s" WattPerSquareMeter Unit = "W/m2" CandelaPerSquareMeter Unit = "cd/m2" Bit Unit = "bit" BitPerSecond Unit = "bit/s" Latitude Unit = "lat" Longitude Unit = "lon" PH Unit = "pH" Decibel Unit = "dB" DBW Unit = "dBW" Bel Unit = "Bspl" Count Unit = "count" Ratio Unit = "/" Percent Unit = "%" RelativeHumidityPercent Unit = "%RH" RemainingBatteryPercent Unit = "%EL" RemainingBatterySeconds Unit = "EL" Rate Unit = "1/s" RPM Unit = "1/min" HeartRate Unit = "beat/min" HeartBeats Unit = "beats" Conductivity Unit = "S/m" )
Unit definitions
type Value ¶
type Value struct { Attributes Value float64 }
Value represents a floating point measurement value. It implements Measurement.
func NewValue ¶
func NewValue(name string, value float64, unit Unit, time time.Time, updateTime time.Duration) *Value
NewValue returns a new Value with the corresponding value and attributes.
func (*Value) Equal ¶
func (v *Value) Equal(ml Measurement) bool
Equal returns true if the given Measurement value is equal.