good morning!!!!

Skip to content
Snippets Groups Projects
transport.go 1.03 KiB
Newer Older
a's avatar
wip
a committed
package codec

import (
	"context"
a's avatar
a committed
	"io"
a's avatar
wip
a committed
)

a's avatar
a  
a committed
// ReaderWriter represents a single stream
// this stream can be used to send/receive an arbitrary amount of requests and notifications
a's avatar
wip
a committed
type ReaderWriter interface {
	Reader
	Writer
}

// Reader can write JSON messages to its underlying connection
// Implementations must be safe for concurrent use
type Reader interface {
	// gets the peer info
	PeerInfo() PeerInfo
	// json.RawMessage can be an array of requests. if it is, then it is a batch request
a's avatar
a committed
	ReadBatch(ctx context.Context) (msgs []*Message, batch bool, err error)
a's avatar
wip
a committed
	// closes the connection
	Close() error
}

a's avatar
a committed
// Writer can write bytes messages to their underlying connection.
a's avatar
wip
a committed
// Implementations must be safe for concurrent use.
type Writer interface {
	// write json blob to stream
a's avatar
a committed
	io.Writer
a's avatar
a committed
	// Flush flushes the writer to the stream  between messages
	Flush() error

a's avatar
wip
a committed
	// Closed returns a channel which is closed when the connection is closed.
a's avatar
ok  
a committed
	Closed() <-chan struct{}
a's avatar
wip
a committed
	// RemoteAddr returns the peer address of the connection.
	RemoteAddr() string
}