|
|
@ -2,11 +2,32 @@ package nhooyrioWebsocketAddons |
|
|
|
|
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
|
|
|
|
"nhooyr.io/websocket" |
|
|
|
"nhooyr.io/websocket/wsjson" |
|
|
|
) |
|
|
|
|
|
|
|
type GosmContainerType struct { |
|
|
|
TagID string `json:"tagid"` |
|
|
|
Attribute string `json:"attribute"` // might left empty
|
|
|
|
Content string `json:"content"` |
|
|
|
} |
|
|
|
|
|
|
|
type GosmContainer []GosmContainerType |
|
|
|
|
|
|
|
func (r *GosmContainer) Gosm2Buffer() (buffer GosmBuffer, err error) { |
|
|
|
buffer, err = json.Marshal(*r) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
type GosmBuffer []byte |
|
|
|
|
|
|
|
func (r *GosmBuffer) Buffer2Gosm() (gosm GosmContainer, err error) { |
|
|
|
err = json.Unmarshal(*r, &gosm) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func WsjsonSend(ctx context.Context, conn *websocket.Conn, sendval interface{}) (err error, receiveval interface{}) { |
|
|
|
err = nil |
|
|
|
|
|
|
|