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

Function GetUint64

parser.go:2106–2136  ·  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

2104// values larger than uint64 return OverflowIntegerError.
2105// SYS-REQ-003
2106func GetUint64(data []byte, keys ...string) (uint64, error) {
2107 v, t, _, _, err := internalGet(data, keys...)
2108 if err != nil {
2109 return 0, err
2110 }
2111
2112 if t != Number {
2113 if t == Null {
2114 return 0, NullValueError
2115 }
2116 return 0, fmt.Errorf("Value is not a number: %s", string(v))
2117 }
2118
2119 if n, ok, _ := parseInt(v); ok {
2120 if n < 0 {
2121 return 0, MalformedValueError
2122 }
2123 return uint64(n), nil
2124 }
2125
2126 n, parseErr := strconv.ParseUint(string(v), 10, 64)
2127 if parseErr == nil {
2128 return n, nil
2129 }
2130
2131 var numErr *strconv.NumError
2132 if errors.As(parseErr, &numErr) && numErr.Err == strconv.ErrRange {
2133 return 0, OverflowIntegerError
2134 }
2135 return 0, MalformedValueError
2136}
2137
2138// SYS-REQ-112
2139func 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