Method: SSHData::Encoding#decode_options
- Defined in:
- lib/ssh_data/encoding.rb
#decode_options(raw, offset = 0) ⇒ Object
Read a series of key/value pairs out of the provided raw data.
raw - A binary String. offset - The offset into raw at which to read (default 0).
Returns an Array including the Hash of decoded keys/values and the Integer number of bytes read.
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/ssh_data/encoding.rb', line 615 def (raw, offset=0) opts_raw, str_read = decode_string(raw, offset) opts_read = 0 opts = {} while opts_raw.bytesize > opts_read key, read = decode_string(opts_raw, opts_read) opts_read += read value_raw, read = decode_string(opts_raw, opts_read) opts_read += read if value_raw.bytesize > 0 opts[key], read = decode_string(value_raw) if read != value_raw.bytesize raise DecodeError, "bad options data" end else opts[key] = true end end if opts_read != opts_raw.bytesize raise DecodeError, "bad options" end [opts, str_read] end |