Skip to content

Commit 0407974

Browse files
committed
msgpack
1 parent 15a3f31 commit 0407974

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

cmd/client/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package client
22

33
import (
44
"bytes"
5-
"encoding/json"
65
"fmt"
76
"io"
87
"log"
@@ -13,6 +12,7 @@ import (
1312
"time"
1413

1514
"github.com/gorilla/websocket"
15+
"github.com/shamaton/msgpack/v2"
1616
)
1717

1818
// Message struct to match the server's message structure
@@ -124,7 +124,7 @@ func HandleClient(port string) {
124124
}
125125

126126
var message Message
127-
if err := json.Unmarshal(messageBytes, &message); err != nil {
127+
if err := msgpack.Unmarshal(messageBytes, &message); err != nil {
128128
log.Printf("Received invaid response from server: %s", string(messageBytes))
129129
continue
130130
}
@@ -172,7 +172,7 @@ func HandleClient(port string) {
172172
}
173173

174174
// Send response back through WebSocket
175-
responseBytes, err := json.Marshal(message)
175+
responseBytes, err := msgpack.Marshal(message)
176176
if err != nil {
177177
log.Printf("Error marshaling response: %v", err)
178178
continue

go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ module github.com/portsicle/portsicle-client
22

33
go 1.23.4
44

5-
require github.com/gorilla/websocket v1.5.3
5+
require (
6+
github.com/gorilla/websocket v1.5.3
7+
github.com/shamaton/msgpack/v2 v2.2.2
8+
)
69

710
require (
811
github.com/inconshreveable/mousetrap v1.1.0 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
44
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
55
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
66
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7+
github.com/shamaton/msgpack/v2 v2.2.2 h1:GOIg0c9LV04VwzOOqZSrmsv/JzjNOOMxnS/HvOHGdgs=
8+
github.com/shamaton/msgpack/v2 v2.2.2/go.mod h1:6khjYnkx73f7VQU7wjcFS9DFjs+59naVWJv1TB7qdOI=
79
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
810
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
911
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=

0 commit comments

Comments
 (0)