tcpclient

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host    string
	Port    int
	Timeout time.Duration
	// contains filtered or unexported fields
}

Client represents a TCP client for testing

func NewClient

func NewClient(host string, port int, timeout time.Duration) *Client

NewClient creates a new TCP client

func (*Client) Close

func (c *Client) Close() error

Close closes the TCP connection

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes a TCP connection

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns whether the client is currently connected

func (*Client) Recv

func (c *Client) Recv() ([]byte, error)

Recv receives data from the TCP connection Returns the raw bytes received (without any parsing)

func (*Client) RecvExact

func (c *Client) RecvExact(n int) ([]byte, error)

RecvExact receives exactly n bytes from the TCP connection Used for reading bulk strings in RESP protocol

func (*Client) Send

func (c *Client) Send(data []byte) error

Send sends data over the TCP connection

type RESPType

type RESPType byte

RESPType represents the type of RESP value

const (
	SimpleString RESPType = '+' // +OK\r\n
	Error        RESPType = '-' // -ERR message\r\n
	BulkString   RESPType = '$' // $123\r\n{data}\r\n
)

type RESPValue

type RESPValue struct {
	Type       RESPType
	RawValue   string      // Raw string value (for + and -)
	JSONValue  interface{} // Parsed JSON value (for $)
	IsNull     bool        // True if $-1\r\n
	BulkLength int         // Length of bulk string
}

RESPValue represents a parsed RESP value

func ParseRESP

func ParseRESP(client *Client) (*RESPValue, error)

ParseRESP parses a RESP response from the client

func (*RESPValue) String

func (v *RESPValue) String() string

String returns a string representation of the RESP value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL