зеркало из https://github.com/golang/tools.git
internal/jsonrpc2: rename NewStream to NewRawStream
NewStream implies the default stream type, which it is not. NewHeaderStream is actually the default choice. Change-Id: I1744d7e902d27c13393f3b367fe2d29e5d7dc283 Reviewed-on: https://go-review.googlesource.com/c/tools/+/231618 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Родитель
535e1470ec
Коммит
33427f1b03
|
@ -111,7 +111,7 @@ func run(ctx context.Context, t *testing.T, withHeaders bool, r io.ReadCloser, w
|
||||||
if withHeaders {
|
if withHeaders {
|
||||||
stream = jsonrpc2.NewHeaderStream(r, w)
|
stream = jsonrpc2.NewHeaderStream(r, w)
|
||||||
} else {
|
} else {
|
||||||
stream = jsonrpc2.NewStream(r, w)
|
stream = jsonrpc2.NewRawStream(r, w)
|
||||||
}
|
}
|
||||||
conn := jsonrpc2.NewConn(stream)
|
conn := jsonrpc2.NewConn(stream)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
|
@ -86,10 +86,10 @@ func (s *PipeServer) Connect(ctx context.Context) *jsonrpc2.Conn {
|
||||||
cReader.Close()
|
cReader.Close()
|
||||||
cWriter.Close()
|
cWriter.Close()
|
||||||
})
|
})
|
||||||
serverStream := jsonrpc2.NewStream(sReader, cWriter)
|
serverStream := jsonrpc2.NewRawStream(sReader, cWriter)
|
||||||
go s.server.ServeStream(ctx, serverStream)
|
go s.server.ServeStream(ctx, serverStream)
|
||||||
|
|
||||||
clientStream := jsonrpc2.NewStream(cReader, sWriter)
|
clientStream := jsonrpc2.NewRawStream(cReader, sWriter)
|
||||||
return jsonrpc2.NewConn(clientStream)
|
return jsonrpc2.NewConn(clientStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,23 +28,23 @@ type Stream interface {
|
||||||
Write(context.Context, Message) (int64, error)
|
Write(context.Context, Message) (int64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStream returns a Stream built on top of an io.Reader and io.Writer
|
// NewRawStream returns a Stream built on top of an io.Reader and io.Writer.
|
||||||
// The messages are sent with no wrapping, and rely on json decode consistency
|
// The messages are sent with no wrapping, and rely on json decode consistency
|
||||||
// to determine message boundaries.
|
// to determine message boundaries.
|
||||||
func NewStream(in io.Reader, out io.Writer) Stream {
|
func NewRawStream(in io.Reader, out io.Writer) Stream {
|
||||||
return &plainStream{
|
return &rawStream{
|
||||||
in: json.NewDecoder(in),
|
in: json.NewDecoder(in),
|
||||||
out: out,
|
out: out,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type plainStream struct {
|
type rawStream struct {
|
||||||
in *json.Decoder
|
in *json.Decoder
|
||||||
outMu sync.Mutex
|
outMu sync.Mutex
|
||||||
out io.Writer
|
out io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *plainStream) Read(ctx context.Context) (Message, int64, error) {
|
func (s *rawStream) Read(ctx context.Context) (Message, int64, error) {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, 0, ctx.Err()
|
return nil, 0, ctx.Err()
|
||||||
|
@ -58,7 +58,7 @@ func (s *plainStream) Read(ctx context.Context) (Message, int64, error) {
|
||||||
return msg, int64(len(raw)), err
|
return msg, int64(len(raw)), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *plainStream) Write(ctx context.Context, msg Message) (int64, error) {
|
func (s *rawStream) Write(ctx context.Context, msg Message) (int64, error) {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return 0, ctx.Err()
|
return 0, ctx.Err()
|
||||||
|
@ -74,7 +74,7 @@ func (s *plainStream) Write(ctx context.Context, msg Message) (int64, error) {
|
||||||
return int64(n), err
|
return int64(n), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHeaderStream returns a Stream built on top of an io.Reader and io.Writer
|
// NewHeaderStream returns a Stream built on top of an io.Reader and io.Writer.
|
||||||
// The messages are sent with HTTP content length and MIME type headers.
|
// The messages are sent with HTTP content length and MIME type headers.
|
||||||
// This is the format used by LSP and others.
|
// This is the format used by LSP and others.
|
||||||
func NewHeaderStream(in io.Reader, out io.Writer) Stream {
|
func NewHeaderStream(in io.Reader, out io.Writer) Stream {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче