-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_wire.go
More file actions
45 lines (35 loc) · 1.06 KB
/
client_wire.go
File metadata and controls
45 lines (35 loc) · 1.06 KB
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
44
45
// 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 dicedb
import (
"fmt"
"net"
"time"
"github.com/sevenDatabase/SevenDB-go/internal"
"github.com/sevenDatabase/SevenDB-go/wire"
)
type ClientWire struct {
*internal.ProtobufTCPWire
}
func NewClientWire(maxMsgSize int, host string, port int) (*ClientWire, *wire.WireError) {
addr := fmt.Sprintf("%s:%d", host, port)
conn, err := net.DialTimeout("tcp", addr, 5*time.Second)
if err != nil {
return nil, &wire.WireError{Kind: wire.NotEstablished, Cause: err}
}
w := &ClientWire{
ProtobufTCPWire: internal.NewProtobufTCPWire(maxMsgSize, conn),
}
return w, nil
}
func (cw *ClientWire) Send(cmd *wire.Command) *wire.WireError {
return cw.ProtobufTCPWire.Send(cmd)
}
func (cw *ClientWire) Receive() (*wire.Result, *wire.WireError) {
resp := &wire.Result{}
err := cw.ProtobufTCPWire.Receive(resp)
return resp, err
}
func (cw *ClientWire) Close() {
cw.ProtobufTCPWire.Close()
}