Files
zeekay 47ce3bad54 codec: rip github.com/luxfi/codec from leaf-misc (Wave 1D)
Replace codec/jsonrpc.Uint32 with an in-package Uint32 JSON wrapper
(peer/jsonnum.go). The Info struct needs a string-encoded uint32 at
the JSON-RPC boundary; no broader codec dependency is needed for that.

Files touched:
- peer/jsonnum.go (new): Uint32 with MarshalJSON/UnmarshalJSON
- peer/info.go: drop codec/jsonrpc import, use local Uint32
- peer/peer.go: drop codec/jsonrpc import, use local Uint32

go.mod direct dep on luxfi/codec removed.
2026-06-05 11:56:54 -07:00

30 lines
775 B
Go

// Copyright (C) 2019-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package peer
import "strconv"
// Uint32 is a uint32 that JSON marshals as a quoted decimal string. Used at
// the JSON-RPC boundary where JS clients lose precision on integers > 2^53.
type Uint32 uint32
// MarshalJSON implements json.Marshaler.
func (u Uint32) MarshalJSON() ([]byte, error) {
return []byte(`"` + strconv.FormatUint(uint64(u), 10) + `"`), nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (u *Uint32) UnmarshalJSON(b []byte) error {
s := string(b)
if s == "null" {
return nil
}
if n := len(s); n >= 2 && s[0] == '"' && s[n-1] == '"' {
s = s[1 : n-1]
}
v, err := strconv.ParseUint(s, 10, 32)
*u = Uint32(v)
return err
}