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

Function GetUint64

parser.go:2146–2176  ·  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

2144// values larger than uint64 return OverflowIntegerError.
2145// SYS-REQ-003
2146func GetUint64(data []byte, keys ...string) (uint64, error) {
2147 v, t, _, _, err := internalGet(data, keys...)
2148 if err != nil {
2149 return 0, err
2150 }
2151
2152 if t != Number {
2153 if t == Null {
2154 return 0, NullValueError
2155 }
2156 return 0, fmt.Errorf("Value is not a number: %s", string(v))
2157 }
2158
2159 if n, ok, _ := parseInt(v); ok {
2160 if n < 0 {
2161 return 0, MalformedValueError
2162 }
2163 return uint64(n), nil
2164 }
2165
2166 n, parseErr := strconv.ParseUint(string(v), 10, 64)
2167 if parseErr == nil {
2168 return n, nil
2169 }
2170
2171 var numErr *strconv.NumError
2172 if errors.As(parseErr, &numErr) && numErr.Err == strconv.ErrRange {
2173 return 0, OverflowIntegerError
2174 }
2175 return 0, MalformedValueError
2176}
2177
2178// SYS-REQ-112
2179func 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