123456789101112131415161718192021222324252627282930313233343536 |
- package klink
- import (
- "github.com/gogf/gf/encoding/gjson"
- "github.com/stretchr/testify/assert"
- "testing"
- )
- func TestDevSend_Marshal(t *testing.T) {
- d := &DevSend{
- Action: "devSend",
- MsgId: 0,
- DeviceCode: "11111",
- Data: &DevSendData{
- Cmd: "powerOn",
- Params: gjson.New(`{}`),
- },
- }
- b, err := d.Marshal()
- if err != nil {
- t.Fatal(err)
- }
- newD := &DevSend{}
- err = newD.UnMarshal(b)
- if err != nil {
- t.Fatal(err)
- }
- assert.Equal(t, d.Action, newD.Action)
- }
- func TestDevSend_UnMarshal(t *testing.T) {
- j := gjson.New(`{"action":"devSend","data":{"cmd":"powerOn","params":{"power":1}},"deviceCode":"5566","msgId":1,"timestamp":1662432310}`)
- params := j.GetJson("data")
- t.Log(params.GetMap("params"))
- }
|