1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-07-03 07:43:40 +02:00

remove mutex, comment fixes

This commit is contained in:
Michał Nowotnik 2022-07-11 10:48:56 +02:00
parent 85ee4c48f5
commit 3d8a093359

View file

@ -198,23 +198,26 @@ type plainObjectStream struct {
conn io.Closer conn io.Closer
decoder *json.Decoder decoder *json.Decoder
encoder *json.Encoder encoder *json.Encoder
mu sync.Mutex
} }
// NewPlainObjectStream creates a buffered stream from a network
// connection (or other similar interface). The underlying
// objectStream produces plain JSON-RPC 2.0 objects without a header.
func NewPlainObjectStream(conn io.ReadWriteCloser) ObjectStream { func NewPlainObjectStream(conn io.ReadWriteCloser) ObjectStream {
os := &plainObjectStream{conn: conn} return &plainObjectStream{
os.encoder = json.NewEncoder(conn) conn: conn,
os.decoder = json.NewDecoder(conn) encoder: json.NewEncoder(conn),
return os decoder: json.NewDecoder(conn),
}
} }
func (os *plainObjectStream) ReadObject(v interface{}) error { func (os *plainObjectStream) ReadObject(v interface{}) error {
return os.decoder.Decode(v) return os.decoder.Decode(v)
} }
// WriteObject serializes a value to JSON and writes it to a stream.
// Not thread-safe, a user must synchronize writes in a multithreaded environment.
func (os *plainObjectStream) WriteObject(v interface{}) error { func (os *plainObjectStream) WriteObject(v interface{}) error {
os.mu.Lock()
defer os.mu.Unlock()
return os.encoder.Encode(v) return os.encoder.Encode(v)
} }