sourcegraph / jsonrpc2

Package jsonrpc2 provides a client and server implementation of JSON-RPC 2.0 (http://www.jsonrpc.org/specification)
MIT License
190 stars 62 forks source link

[#57] Fix and deprecate PlainObjectCodec #58

Closed mnowotnik closed 2 years ago

mnowotnik commented 2 years ago

This change fixes a bug that causes PlainObjectCodec to lose additional messages from stream. json.Decoder has an internal buffer that reads more than one message, but is discarded after every use. Now PlainObjectCodec reuses encoder and decoder within a buffered stream, however using it directly in your code retains the old, incorrect behaviour.

A user should now use plainObjectStream if he needs plain JSON-RPC 2.0 stream without headers. NewPlainObjectStream method has been added for this reason.

fixes #57