Module: SpinelKit
- Defined in:
- lib/spinel_kit/hex.rb,
lib/spinel_kit/log.rb,
lib/spinel_kit/url.rb,
lib/spinel_kit/json.rb,
lib/spinel_kit/json_decoder.rb
Overview
VENDORED from OriPekelman/spinelkit @ 09e8558 -- DO NOT EDIT HERE.
Edit upstream and re-sync with make vendor-spinelkit.
SpinelKit::Json -- Spinel-safe JSON DECODERS (flat-key, top-level only).
The decode half of the codec; encoders are in spinel_kit/json.rb. Split out so an encode-only consumer never compiles these walkers (their dead-code degradation otherwise widens the encoders' string args to int -- see the header of json.rb and docs/spinel-discipline.md).
get_str(s, key) finds the entry for key in the top-level object literal
s and returns its value as a string. Returns "" when key is absent or
the value isn't a string. Same shape for get_int. has_key?(s, key)
returns a boolean independent of value type. The parser is a hand-rolled
state machine that walks one { "k": <value>, ... } pair at a time,
skipping over any value (including nested objects / arrays) it doesn't need.
Strings inside values are honoured for escape sequences so that \" doesn't
terminate the string and corrupt the walk. Decodes the escape sequences
SpinelKit::Json.escape produces.