summaryrefslogtreecommitdiff
path: root/internal/session/spec.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/session/spec.go')
-rw-r--r--internal/session/spec.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/session/spec.go b/internal/session/spec.go
index 2d1b77d..0a6ad4e 100644
--- a/internal/session/spec.go
+++ b/internal/session/spec.go
@@ -1,6 +1,8 @@
package session
import (
+ "encoding/base64"
+ "encoding/json"
"fmt"
"strings"
@@ -45,6 +47,30 @@ func (s Spec) Commands() ([]string, error) {
}
}
+// StartCommand returns the SESSION START command for this specification.
+func (s Spec) StartCommand() (string, error) {
+ payload, err := s.encodedPayload()
+ if err != nil {
+ return "", err
+ }
+
+ return fmt.Sprintf("SESSION START %s", payload), nil
+}
+
+// UpdateCommand returns the SESSION UPDATE command for this specification.
+func (s Spec) UpdateCommand(generation uint64) (string, error) {
+ payload, err := s.encodedPayload()
+ if err != nil {
+ return "", err
+ }
+
+ if generation == 0 {
+ return fmt.Sprintf("SESSION UPDATE %s", payload), nil
+ }
+
+ return fmt.Sprintf("SESSION UPDATE %d %s", generation, payload), nil
+}
+
func (s Spec) queryCommands() ([]string, error) {
if s.Mode != omode.MapClient && s.Mode != omode.TailClient {
return nil, fmt.Errorf("session spec query mode requires map or tail mode, got %s", s.Mode)
@@ -122,3 +148,12 @@ func splitFiles(what string) []string {
}
return files
}
+
+func (s Spec) encodedPayload() (string, error) {
+ payload, err := json.Marshal(s)
+ if err != nil {
+ return "", fmt.Errorf("marshal session spec: %w", err)
+ }
+
+ return base64.StdEncoding.EncodeToString(payload), nil
+}