MCPcopy Create free account
hub / github.com/buger/jsonparser / GetUint64

Function GetUint64

parser.go:2014–2044  ·  view source on GitHub ↗

GetUint64 returns the value retrieved by internalGet, cast to a uint64 if possible. Negative values and malformed integers return MalformedValueError; values larger than uint64 return OverflowIntegerError. SYS-REQ-003

(data []byte, keys ...string)

Source from the content-addressed store, hash-verified

2012// values larger than uint64 return OverflowIntegerError.
2013// SYS-REQ-003
2014func GetUint64(data []byte, keys ...string) (uint64, error) {
2015 v, t, _, _, err := internalGet(data, keys...)
2016 if err != nil {
2017 return 0, err
2018 }
2019
2020 if t != Number {
2021 if t == Null {
2022 return 0, NullValueError
2023 }
2024 return 0, fmt.Errorf("Value is not a number: %s", string(v))
2025 }
2026
2027 if n, ok, _ := parseInt(v); ok {
2028 if n < 0 {
2029 return 0, MalformedValueError
2030 }
2031 return uint64(n), nil
2032 }
2033
2034 n, parseErr := strconv.ParseUint(string(v), 10, 64)
2035 if parseErr == nil {
2036 return n, nil
2037 }
2038
2039 var numErr *strconv.NumError
2040 if errors.As(parseErr, &numErr) && numErr.Err == strconv.ErrRange {
2041 return 0, OverflowIntegerError
2042 }
2043 return 0, MalformedValueError
2044}
2045
2046// SYS-REQ-112
2047func containerStart(data []byte, open byte, keys ...string) (int, error) {

Callers 1

TestGetUint64Function · 0.85

Calls 2

internalGetFunction · 0.85
parseIntFunction · 0.85

Tested by 1

TestGetUint64Function · 0.68