summaryrefslogtreecommitdiffstats
path: root/vendor/lukechampine.com/uint128/uint128.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2022-11-27 00:42:16 +0100
committerGitHub <noreply@github.com>2022-11-27 00:42:16 +0100
commit4fd0a7672777f0ed15692ae2ba47838208537558 (patch)
treeb119834a8b9ee78aa8f1b2ad05efa7da50516cbf /vendor/lukechampine.com/uint128/uint128.go
parent6da9d567dc9195e9a5211f23a6795a41f56a1bfc (diff)
downloadmatterbridge-msglm-4fd0a7672777f0ed15692ae2ba47838208537558.tar.gz
matterbridge-msglm-4fd0a7672777f0ed15692ae2ba47838208537558.tar.bz2
matterbridge-msglm-4fd0a7672777f0ed15692ae2ba47838208537558.zip
Update dependencies (#1929)
Diffstat (limited to 'vendor/lukechampine.com/uint128/uint128.go')
-rw-r--r--vendor/lukechampine.com/uint128/uint128.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/vendor/lukechampine.com/uint128/uint128.go b/vendor/lukechampine.com/uint128/uint128.go
index 0b74b9fc..04e65783 100644
--- a/vendor/lukechampine.com/uint128/uint128.go
+++ b/vendor/lukechampine.com/uint128/uint128.go
@@ -2,6 +2,8 @@ package uint128 // import "lukechampine.com/uint128"
import (
"encoding/binary"
+ "errors"
+ "fmt"
"math"
"math/big"
"math/bits"
@@ -385,6 +387,21 @@ func (u Uint128) Big() *big.Int {
return i
}
+// Scan implements fmt.Scanner.
+func (u *Uint128) Scan(s fmt.ScanState, ch rune) error {
+ i := new(big.Int)
+ if err := i.Scan(s, ch); err != nil {
+ return err
+ } else if i.Sign() < 0 {
+ return errors.New("value cannot be negative")
+ } else if i.BitLen() > 128 {
+ return errors.New("value overflows Uint128")
+ }
+ u.Lo = i.Uint64()
+ u.Hi = i.Rsh(i, 64).Uint64()
+ return nil
+}
+
// New returns the Uint128 value (lo,hi).
func New(lo, hi uint64) Uint128 {
return Uint128{lo, hi}
@@ -412,6 +429,12 @@ func FromBig(i *big.Int) (u Uint128) {
panic("value overflows Uint128")
}
u.Lo = i.Uint64()
- u.Hi = new(big.Int).Rsh(i, 64).Uint64()
+ u.Hi = i.Rsh(i, 64).Uint64()
return u
}
+
+// FromString parses s as a Uint128 value.
+func FromString(s string) (u Uint128, err error) {
+ _, err = fmt.Sscan(s, &u)
+ return
+}