Initial, working but only with viewport height adjusted a little bit
This commit is contained in:
42
internal/bridge/protocol.go
Normal file
42
internal/bridge/protocol.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package bridge
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"maps"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
type CommandType string
|
||||
|
||||
const (
|
||||
ContinueCommand CommandType = "continue"
|
||||
BreakCommand CommandType = "break"
|
||||
LocalsCommand CommandType = "locals"
|
||||
)
|
||||
|
||||
func makeCommand(cmd CommandType, values map[string]any) (requestId string, request string) {
|
||||
m := make(map[string]any, len(values)+2)
|
||||
maps.Copy(m, values)
|
||||
|
||||
requestId = randString(8)
|
||||
|
||||
m["cmd"] = cmd
|
||||
m["request_id"] = requestId
|
||||
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
panic("failed to marshal command " + err.Error())
|
||||
}
|
||||
|
||||
return requestId, string(b)
|
||||
}
|
||||
|
||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
func randString(n int) string {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
Reference in New Issue
Block a user