summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-20 17:42:56 +0300
committerValery Piashchynski <[email protected]>2020-12-20 17:42:56 +0300
commitfe0109a3b19ee82bd7bfbb57eae6b5b5166d7068 (patch)
tree52fd2960cb440c99163738fcfeeb6df465662155 /internal
parent349088db2081704e15699ce1e6f6b1f8898bd336 (diff)
Latest goridge version support
Diffstat (limited to 'internal')
-rwxr-xr-xinternal/protocol.go37
1 files changed, 19 insertions, 18 deletions
diff --git a/internal/protocol.go b/internal/protocol.go
index 5aa681eb..a099ce4d 100755
--- a/internal/protocol.go
+++ b/internal/protocol.go
@@ -5,7 +5,8 @@ import (
j "github.com/json-iterator/go"
"github.com/spiral/errors"
- "github.com/spiral/goridge/v3"
+ "github.com/spiral/goridge/v3/interfaces/relay"
+ "github.com/spiral/goridge/v3/pkg/frame"
)
var json = j.ConfigCompatibleWithStandardLibrary
@@ -18,39 +19,39 @@ type pidCommand struct {
Pid int `json:"pid"`
}
-func SendControl(rl goridge.Relay, v interface{}) error {
+func SendControl(rl relay.Relay, payload interface{}) error {
const op = errors.Op("send control frame")
- frame := goridge.NewFrame()
- frame.WriteVersion(goridge.VERSION_1)
- frame.WriteFlags(goridge.CONTROL)
+ fr := frame.NewFrame()
+ fr.WriteVersion(frame.VERSION_1)
+ fr.WriteFlags(frame.CONTROL)
- if data, ok := v.([]byte); ok {
+ if data, ok := payload.([]byte); ok {
// check if payload no more that 4Gb
if uint32(len(data)) > ^uint32(0) {
return errors.E(op, errors.Str("payload is more that 4gb"))
}
- frame.WritePayloadLen(uint32(len(data)))
- frame.WritePayload(data)
- frame.WriteCRC()
+ fr.WritePayloadLen(uint32(len(data)))
+ fr.WritePayload(data)
+ fr.WriteCRC()
- err := rl.Send(frame)
+ err := rl.Send(fr)
if err != nil {
return errors.E(op, err)
}
return nil
}
- data, err := json.Marshal(v)
+ data, err := json.Marshal(payload)
if err != nil {
return errors.E(op, errors.Errorf("invalid payload: %s", err))
}
- frame.WritePayloadLen(uint32(len(data)))
- frame.WritePayload(data)
- frame.WriteCRC()
+ fr.WritePayloadLen(uint32(len(data)))
+ fr.WritePayload(data)
+ fr.WriteCRC()
- err = rl.Send(frame)
+ err = rl.Send(fr)
if err != nil {
return errors.E(op, err)
}
@@ -58,14 +59,14 @@ func SendControl(rl goridge.Relay, v interface{}) error {
return nil
}
-func FetchPID(rl goridge.Relay) (int64, error) {
+func FetchPID(rl relay.Relay) (int64, error) {
const op = errors.Op("fetchPID")
err := SendControl(rl, pidCommand{Pid: os.Getpid()})
if err != nil {
return 0, errors.E(op, err)
}
- frameR := goridge.NewFrame()
+ frameR := frame.NewFrame()
err = rl.Receive(frameR)
if !frameR.VerifyCRC() {
return 0, errors.E(op, errors.Str("CRC mismatch"))
@@ -79,7 +80,7 @@ func FetchPID(rl goridge.Relay) (int64, error) {
flags := frameR.ReadFlags()
- if flags&(byte(goridge.CONTROL)) == 0 {
+ if flags&(byte(frame.CONTROL)) == 0 {
return 0, errors.E(op, errors.Str("unexpected response, header is missing, no CONTROL flag"))
}