mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-06-16 04:04:56 +02:00
Add pluggable transport interface + WebSocket support
simplify API by using interface{}, rename from transport -> stream
add WebSocket transport in websocket subpackage
do not buffer in ReadObject, rename GetObjectReader/ReadObject -> NextObjectReader
use xtest (jsonrpc2_test) package to allow us to test subpackages that depend on us (in a future change)
factor out vscode-specific transport code and allow pluggable transports
remove Server (unused) and Serve (unnecessary):
The Serve func had nothing specific to JSON-RPC; it was just a loop
around (net.Listener).Accept. It added no value.
This commit is contained in:
parent
9fdd802ab4
commit
6e06d561ec
6 changed files with 416 additions and 194 deletions
34
codec_test.go
Normal file
34
codec_test.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package jsonrpc2
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVarintObjectCodec(t *testing.T) {
|
||||
want := 789
|
||||
var buf bytes.Buffer
|
||||
if err := (VarintObjectCodec{}).WriteObject(&buf, want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var v int
|
||||
if err := (VarintObjectCodec{}).ReadObject(bufio.NewReader(&buf), &v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := want; v != want {
|
||||
t.Errorf("got %v, want %v", v, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVSCodeObjectCodec_ReadObject(t *testing.T) {
|
||||
s := "Content-Type: foo\r\nContent-Length: 123\r\n\r\n789"
|
||||
var v int
|
||||
if err := (VSCodeObjectCodec{}).ReadObject(bufio.NewReader(strings.NewReader(s)), &v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := 789; v != want {
|
||||
t.Errorf("got %v, want %v", v, want)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue