Skip to content

Commit

Permalink
Supported x32 architecture.
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Oct 3, 2021
1 parent 927c0b8 commit 95b5076
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions jrpc2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net"
"os"
"sync"
"math"
"sync/atomic"
"time"
)
Expand All @@ -23,7 +24,7 @@ import (
type Client struct {
requestQueue chan *Request
pending sync.Map // map[string]chan *RawResponse
requestCounter int64
requestCounter uint32
shutdown bool
timeout time.Duration
}
Expand Down Expand Up @@ -226,6 +227,9 @@ func handleReply(rawResp *RawResponse, resp interface{}) error {

// for now, use a counter as the id for requests
func (c *Client) NextId() *Id {
val := atomic.AddInt64(&c.requestCounter, 1)
if c.requestCounter == math.MaxUint32 {
atomic.StoreUint32(&c.requestCounter, 0)
}
val := atomic.AddUint32(&c.requestCounter, 1)
return NewIdAsInt(val)
}
10 changes: 5 additions & 5 deletions jrpc2/jsonrpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const InternalErr = -32603
// 'actual' type of it so when we send it back over the
// wire, we don't confuse the other side.
type Id struct {
intVal int64
intVal uint32
strVal string
}

Expand All @@ -52,11 +52,11 @@ func (id *Id) UnmarshalJSON(data []byte) error {
id.strVal = string(data[1 : len(data)-1])
return nil
case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
val, err := strconv.ParseInt(string(data), 10, 64)
val, err := strconv.ParseUint(string(data), 10, 32)
if err != nil {
return NewError(nil, InvalidRequest, fmt.Sprintf("Invalid Id value: %s", string(data)))
}
id.intVal = val
id.intVal = uint32(val)
return nil
case '{': // objects not allowed!
fallthrough
Expand All @@ -75,7 +75,7 @@ func (id Id) String() string {
if id.strVal != "" {
return id.strVal
}
return strconv.FormatInt(id.intVal, 10)
return strconv.FormatInt(int64(id.intVal), 10)
}

func NewId(val string) *Id {
Expand All @@ -84,7 +84,7 @@ func NewId(val string) *Id {
}
}

func NewIdAsInt(val int64) *Id {
func NewIdAsInt(val uint32) *Id {
return &Id{
intVal: val,
}
Expand Down

0 comments on commit 95b5076

Please sign in to comment.