diff --git a/client.go b/client.go index 6463ef51bd8a8159538663c83a432d13884dfb3f..8de58cc0be1090e445b2bea2bdd182850a19ea2f 100644 --- a/client.go +++ b/client.go @@ -60,7 +60,7 @@ type BatchElem struct { type Client struct { isHTTP bool // connection type: http, ws or ipc - idCounter uint32 + idCounter uint64 r Router // This function, if non-nil, is called when the connection is lost. @@ -218,8 +218,8 @@ func initClient(conn ServerCodec, r Router) *Client { } func (c *Client) nextID() *ID { - id := atomic.AddUint32(&c.idCounter, 1) - return NewNumberIDPtr(int32(id)) + id := atomic.AddUint64(&c.idCounter, 1) + return NewNumberIDPtr(int64(id)) } // SupportedModules calls the rpc_modules method, retrieving the list of diff --git a/json.go b/json.go index 0ea97ce2e77d2b86cbed535f228cc8a215efa247..d1a34e501749209c98b485b60bc87c551945c9c0 100644 --- a/json.go +++ b/json.go @@ -57,7 +57,7 @@ type jsonrpcMessage struct { func MakeCall(id int, method string, params []any) *JsonRpcMessage { return &JsonRpcMessage{ - ID: NewNumberIDPtr(int32(id)), + ID: NewNumberIDPtr(int64(id)), } } diff --git a/wire.go b/wire.go index bfc334357e20f70a161a0ebcbb1837071ed16506..4a13caea499c39dfbedf6cf7627fe58d5c5a8fa0 100644 --- a/wire.go +++ b/wire.go @@ -43,7 +43,7 @@ func (version) UnmarshalJSON(data []byte) error { // alternatively, ID can be null type ID struct { name string - number int32 + number int64 null bool } @@ -56,7 +56,7 @@ var ( ) // NewNumberID returns a new number request ID. -func NewNumberID(v int32) ID { return *NewNumberIDPtr(v) } +func NewNumberID(v int64) ID { return *NewNumberIDPtr(v) } // NewStringID returns a new string request ID. func NewStringID(v string) ID { return *NewStringIDPtr(v) } @@ -64,7 +64,7 @@ func NewStringID(v string) ID { return *NewStringIDPtr(v) } // NewStringID returns a new string request ID. func NewNullID() ID { return *NewNullIDPtr() } -func NewNumberIDPtr(v int32) *ID { return &ID{number: v} } +func NewNumberIDPtr(v int64) *ID { return &ID{number: v} } func NewStringIDPtr(v string) *ID { return &ID{name: v} } func NewNullIDPtr() *ID { return &ID{null: true} } diff --git a/wsjson/writer_test.go b/wsjson/writer_test.go new file mode 100644 index 0000000000000000000000000000000000000000..926abb24756646da686927cc2f518873144c039f --- /dev/null +++ b/wsjson/writer_test.go @@ -0,0 +1,30 @@ +package wsjson + +import ( + "bytes" + "encoding/json" + "io" + "log" + "testing" +) + +type noTrailingNewlineWriter struct { + w io.Writer +} + +func (n *noTrailingNewlineWriter) Write(xs []byte) (int, error) { + if xs[len(xs)-1] == '\n' { + xs = xs[:len(xs)-1] + } + return n.w.Write(xs) +} + +func TestNoTrailingNewlineWriter(t *testing.T) { + buf := new(bytes.Buffer) + wr := &noTrailingNewlineWriter{w: buf} + enc := json.NewEncoder(wr) + enc.Encode(map[string]any{"hi": "there", "how": "are", "you": "?"}) + enc.Encode(map[string]any{"hi": "there", "how": "are", "you": "?"}) + enc.Encode(map[string]any{"hi": "there", "how": "are", "you": "?"}) + log.Println(string(buf.Bytes())) +}