Sha256: 66ec6ac2e8f075158bf87c25e4e1f17b569f4fd261ab0b3f4a78253710c2f969

Contents?: true

Size: 1.07 KB

Versions: 59

Compression:

Stored size: 1.07 KB

Contents

# -*- coding: binary -*-
module Dap
module Proto
class WDBRPC

  def self.wdbrpc_checksum(data)
    sum = 0
    data.unpack("n*").each {|c| sum += c }
    sum = (sum & 0xffff) + (sum >> 16)
    (~sum)
  end

  def self.wdbrpc_decode_str(data)
    return if data.length < 4
    slen = data.slice!(0,4).unpack("N")[0]
    return "" if slen == 0
    while (slen % 4 != 0)
      slen += 1
    end

    data.slice!(0,slen).to_s.split("\x00")[0]
  end

  def self.wdbrpc_decode_int(data)
    return if data.length < 4
    data.slice!(0,4).unpack("N")[0]
  end

  def self.wdbrpc_decode_arr(data, dtype)
    return if data.length < 4
    res = []

    alen = data.slice!(0,4).unpack("N")[0]
    return res if alen == 0

    1.upto(alen) do |idx|
      case dtype
      when :int
        res << wdbrpc_decode_int(data)
      when :str
        res << wdbrpc_decode_str(data)
      when :bool
        res << wdbrpc_decode_bool(data)
      end
    end

    res
  end

  def self.wdbrpc_decode_bool(data)
    return if data.length < 4
    (data.slice!(0,4).unpack("N")[0] == 0) ? false : true
  end


end
end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
dap-1.3.1 lib/dap/proto/wdbrpc.rb
dap-1.3.0 lib/dap/proto/wdbrpc.rb
dap-1.2.9 lib/dap/proto/wdbrpc.rb
dap-1.2.8 lib/dap/proto/wdbrpc.rb
dap-1.2.7 lib/dap/proto/wdbrpc.rb
dap-1.2.6 lib/dap/proto/wdbrpc.rb
dap-1.2.5 lib/dap/proto/wdbrpc.rb
dap-1.2.4 lib/dap/proto/wdbrpc.rb
dap-1.2.3 lib/dap/proto/wdbrpc.rb
dap-1.2.2 lib/dap/proto/wdbrpc.rb
dap-1.2.1 lib/dap/proto/wdbrpc.rb
dap-1.2.0 lib/dap/proto/wdbrpc.rb
dap-1.0.2 lib/dap/proto/wdbrpc.rb
dap-1.0.1 lib/dap/proto/wdbrpc.rb
dap-1.0.0 lib/dap/proto/wdbrpc.rb
dap-0.1.24 lib/dap/proto/wdbrpc.rb
dap-0.1.23 lib/dap/proto/wdbrpc.rb
dap-0.1.22 lib/dap/proto/wdbrpc.rb
dap-0.1.21 lib/dap/proto/wdbrpc.rb
dap-0.1.20 lib/dap/proto/wdbrpc.rb