MCPcopy Index your code
hub / github.com/cisco/senml / ExampleEncode2

Function ExampleEncode2

senml_test.go:28–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26}
27
28func ExampleEncode2() {
29 v1 := 23.5
30 v2 := 23.6
31 s := senml.SenML{
32 Records: []senml.SenMLRecord{
33 senml.SenMLRecord{Value: &v1, Unit: "Cel", BaseName: "urn:dev:ow:10e2073a01080063", Time: 1.276020076305e+09},
34 senml.SenMLRecord{Value: &v2, Unit: "Cel", Time: 1.276020091305e+09},
35 },
36 }
37
38 dataOut, err := senml.Encode(s, senml.JSON, senml.OutputOptions{})
39 if err != nil {
40 fmt.Println("Encode of SenML failed")
41 } else {
42 fmt.Println(string(dataOut))
43 }
44 // Output: [{"bn":"urn:dev:ow:10e2073a01080063","u":"Cel","t":1276020076.305,"v":23.5},{"u":"Cel","t":1276020091.305,"v":23.6}]
45}
46
47type TestVector struct {
48 testDecode bool

Callers

nothing calls this directly

Calls 1

EncodeFunction · 0.92

Tested by

no test coverage detected