Skip to content

Commit c93221c

Browse files
authored
Use io.ReadWriteCloser instead of net.Conn as connection type (#14)
The connection of jsonrpc should not be limited to net.Conn, but it can support other connection types (e.g. stdin/stdout) as long as it implements io.ReadWriteCloser.
1 parent 5b4cf32 commit c93221c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

stream.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"fmt"
1010
"io"
11-
"net"
1211
"strconv"
1312
"strings"
1413

@@ -38,7 +37,7 @@ const (
3837
//
3938
// It is responsible for the framing and encoding of messages into wire form.
4039
// NewRawStream and NewStream are implementations of a Framer.
41-
type Framer func(conn net.Conn) Stream
40+
type Framer func(conn io.ReadWriteCloser) Stream
4241

4342
// Stream abstracts the transport mechanics from the JSON RPC protocol.
4443
//
@@ -61,15 +60,15 @@ type Stream interface {
6160
}
6261

6362
type rawStream struct {
64-
conn net.Conn
63+
conn io.ReadWriteCloser
6564
in *json.Decoder
6665
}
6766

68-
// NewRawStream returns a Stream built on top of a net.Conn.
67+
// NewRawStream returns a Stream built on top of a io.ReadWriteCloser.
6968
//
7069
// The messages are sent with no wrapping, and rely on json decode consistency
7170
// to determine message boundaries.
72-
func NewRawStream(conn net.Conn) Stream {
71+
func NewRawStream(conn io.ReadWriteCloser) Stream {
7372
return &rawStream{
7473
conn: conn,
7574
in: json.NewDecoder(conn),
@@ -120,15 +119,15 @@ func (s *rawStream) Close() error {
120119
}
121120

122121
type stream struct {
123-
conn net.Conn
122+
conn io.ReadWriteCloser
124123
in *bufio.Reader
125124
}
126125

127-
// NewStream returns a Stream built on top of a net.Conn.
126+
// NewStream returns a Stream built on top of a io.ReadWriteCloser.
128127
//
129128
// The messages are sent with HTTP content length and MIME type headers.
130129
// This is the format used by LSP and others.
131-
func NewStream(conn net.Conn) Stream {
130+
func NewStream(conn io.ReadWriteCloser) Stream {
132131
return &stream{
133132
conn: conn,
134133
in: bufio.NewReader(conn),

0 commit comments

Comments
 (0)