mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-06-16 04:04:56 +02:00
Add PlainObjectCodec (#45)
This commit is contained in:
parent
08fd77d0de
commit
99f63e011f
2 changed files with 66 additions and 4 deletions
13
stream.go
13
stream.go
|
|
@ -162,3 +162,16 @@ func (VSCodeObjectCodec) ReadObject(stream *bufio.Reader, v interface{}) error {
|
|||
}
|
||||
return json.NewDecoder(io.LimitReader(stream, int64(contentLength))).Decode(v)
|
||||
}
|
||||
|
||||
// PlainObjectCodec reads/writes plain JSON-RPC 2.0 objects without a header.
|
||||
type PlainObjectCodec struct{}
|
||||
|
||||
// WriteObject implements ObjectCodec.
|
||||
func (PlainObjectCodec) WriteObject(stream io.Writer, v interface{}) error {
|
||||
return json.NewEncoder(stream).Encode(v)
|
||||
}
|
||||
|
||||
// ReadObject implements ObjectCodec.
|
||||
func (PlainObjectCodec) ReadObject(stream *bufio.Reader, v interface{}) error {
|
||||
return json.NewDecoder(stream).Decode(v)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue