Class: Dap::Proto::WDBRPC

Inherits:
Object
  • Object
show all
Defined in:
lib/dap/proto/wdbrpc.rb

Class Method Summary collapse

Class Method Details

.wdbrpc_checksum(data) ⇒ Object



6
7
8
9
10
11
# File 'lib/dap/proto/wdbrpc.rb', line 6

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

.wdbrpc_decode_arr(data, dtype) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dap/proto/wdbrpc.rb', line 29

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

.wdbrpc_decode_bool(data) ⇒ Object



50
51
52
53
# File 'lib/dap/proto/wdbrpc.rb', line 50

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

.wdbrpc_decode_int(data) ⇒ Object



24
25
26
27
# File 'lib/dap/proto/wdbrpc.rb', line 24

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

.wdbrpc_decode_str(data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/dap/proto/wdbrpc.rb', line 13

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