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)
| 1554 | // If key data type do not match, it will return error. |
| 1555 | // SYS-REQ-005, SYS-REQ-079 |
| 1556 | func GetBoolean(data []byte, keys ...string) (val bool, err error) { |
| 1557 | v, t, _, e := Get(data, keys...) |
| 1558 | |
| 1559 | if e != nil { |
| 1560 | return false, e |
| 1561 | } |
| 1562 | |
| 1563 | if t != Boolean { |
| 1564 | if t == Null { |
| 1565 | return false, NullValueError |
| 1566 | } |
| 1567 | return false, fmt.Errorf("Value is not a boolean: %s", string(v)) |
| 1568 | } |
| 1569 | |
| 1570 | return ParseBoolean(v) |
| 1571 | } |
| 1572 | |
| 1573 | // ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness) |
| 1574 | // SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066 |