mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-06-16 04:04:56 +02:00
remove mutex, comment fixes
This commit is contained in:
parent
85ee4c48f5
commit
3d8a093359
1 changed files with 10 additions and 7 deletions
17
stream.go
17
stream.go
|
|
@ -198,23 +198,26 @@ type plainObjectStream struct {
|
|||
conn io.Closer
|
||||
decoder *json.Decoder
|
||||
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 {
|
||||
os := &plainObjectStream{conn: conn}
|
||||
os.encoder = json.NewEncoder(conn)
|
||||
os.decoder = json.NewDecoder(conn)
|
||||
return os
|
||||
return &plainObjectStream{
|
||||
conn: conn,
|
||||
encoder: json.NewEncoder(conn),
|
||||
decoder: json.NewDecoder(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (os *plainObjectStream) ReadObject(v interface{}) error {
|
||||
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 {
|
||||
os.mu.Lock()
|
||||
defer os.mu.Unlock()
|
||||
return os.encoder.Encode(v)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue