wireclient

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package wireclient provides low-level wire protocol client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn represents a single client connection.

It is not safe for concurrent use.

func Connect

func Connect(ctx context.Context, uri string, l *slog.Logger) (*Conn, error)

Connect creates a new connection for the given MongoDB URI.

Context can be used to cancel the connection attempt. Canceling the context after the connection is established has no effect.

The passed logger will be used only for debug-level messages.

func New

func New(c net.Conn, l *slog.Logger) *Conn

New wraps the given connection.

The passed logger will be used only for debug-level messages.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) Read

func (c *Conn) Read(ctx context.Context) (*wire.MsgHeader, wire.MsgBody, error)

Read reads the next message from the connection.

Passed context's deadline is honored if set.

func (*Conn) Request

func (c *Conn) Request(ctx context.Context, header *wire.MsgHeader, body wire.MsgBody) (*wire.MsgHeader, wire.MsgBody, error)

Request sends the given request to the connection and returns the response. If header's MessageLength or RequestID are not specified, it assigns the proper values. For header's OpCode the wire.OpCodeMsg is used as default.

Passed context's deadline is honored if set.

It returns errors only for request/response parsing or connection issues. All protocol-level errors are stored inside response.

func (*Conn) Write

func (c *Conn) Write(ctx context.Context, header *wire.MsgHeader, body wire.MsgBody) error

Write writes the given message to the connection.

Passed context's deadline is honored if set.

func (*Conn) WriteRaw

func (c *Conn) WriteRaw(ctx context.Context, b []byte) error

WriteRaw writes the given raw bytes to the connection.

Passed context's deadline is honored if set.

Jump to

Keyboard shortcuts

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