-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_wire.go
43 lines (34 loc) · 924 Bytes
/
client_wire.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2022-present, DiceDB contributors
// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information.
package wire
import (
"fmt"
"net"
"time"
"wire/internal"
)
type ClientWire struct {
*internal.ProtobufTCPWire
}
func NewClientWire(maxMsgSize int, host string, port int) (*ClientWire, error) {
addr := fmt.Sprintf("%s:%d", host, port)
conn, err := net.DialTimeout("tcp", addr, 5*time.Second)
if err != nil {
return nil, err
}
wire := &ClientWire{
ProtobufTCPWire: internal.NewProtobufTCPWire(maxMsgSize, conn),
}
return wire, nil
}
func (cw *ClientWire) Send(cmd *Command) error {
return cw.ProtobufTCPWire.Send(cmd)
}
func (cw *ClientWire) Receive() (*Response, error) {
resp := &Response{}
err := cw.ProtobufTCPWire.Receive(resp)
return resp, err
}
func (cw *ClientWire) Close() {
cw.ProtobufTCPWire.Close()
}