GetBoolean returns the value retrieved by `Get`, cast to a bool if possible. The offset is the same as in `Get`. If key data type do not match, it will return error. SYS-REQ-005, SYS-REQ-079
(data []byte, keys ...string)
| 1920 | // If key data type do not match, it will return error. |
| 1921 | // SYS-REQ-005, SYS-REQ-079 |
| 1922 | func GetBoolean(data []byte, keys ...string) (val bool, err error) { |
| 1923 | v, t, _, e := Get(data, keys...) |
| 1924 | |
| 1925 | if e != nil { |
| 1926 | return false, e |
| 1927 | } |
| 1928 | |
| 1929 | if t != Boolean { |
| 1930 | if t == Null { |
| 1931 | return false, NullValueError |
| 1932 | } |
| 1933 | return false, fmt.Errorf("Value is not a boolean: %s", string(v)) |
| 1934 | } |
| 1935 | |
| 1936 | return ParseBoolean(v) |
| 1937 | } |
| 1938 | |
| 1939 | // ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness) |
| 1940 | // SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066 |