Class: ZScan::BSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/zscan/bspec.rb

Instance Method Summary collapse

Constructor Details

#initialize(&p) ⇒ BSpec

Returns a new instance of BSpec.


16
17
18
# File 'lib/zscan/bspec.rb', line 16

def initialize &p
  instance_eval &p
end

Instance Method Details

#_append_expect(expect_i, pack_format, opts) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/zscan/bspec.rb', line 4

def _append_expect expect_i, pack_format, opts
  if opts.is_a?(Hash)
    expect = opts[:expect]
    if expect.is_a?(Integer) and opts.size == 1
      ZScan::BSpec._append self, expect_i
      ZScan::BSpec._append_expect self, [expect].pack(pack_format)
    else
      raise ArgumentError, "only :expect option allowed, but got #{opts.inspect}"
    end
  end
end

#doubleObject Also known as: double_le


101
102
103
# File 'lib/zscan/bspec.rb', line 101

def double
  ZScan::BSpec._append self, 21
end

#double_swapObject Also known as: double_be


105
106
107
# File 'lib/zscan/bspec.rb', line 105

def double_swap
  ZScan::BSpec._append self, 22
end

#int16(opts = nil) ⇒ Object Also known as: int16_le


31
32
33
34
# File 'lib/zscan/bspec.rb', line 31

def int16 opts=nil
  _append_expect 2, (BSpec.big_endian? ? 's>' : 's<'), opts
  ZScan::BSpec._append self, 7
end

#int16_swap(opts = nil) ⇒ Object Also known as: int16_be


36
37
38
39
# File 'lib/zscan/bspec.rb', line 36

def int16_swap opts=nil
  _append_expect 2, (BSpec.big_endian? ? 's<' : 's>'), opts
  ZScan::BSpec._append self, 8
end

#int32(opts = nil) ⇒ Object Also known as: int32_le


41
42
43
44
# File 'lib/zscan/bspec.rb', line 41

def int32 opts=nil
  _append_expect 3, (BSpec.big_endian? ? 'l>' : 'l<'), opts
  ZScan::BSpec._append self, 9
end

#int32_swap(opts = nil) ⇒ Object Also known as: int32_be


46
47
48
49
# File 'lib/zscan/bspec.rb', line 46

def int32_swap opts=nil
  _append_expect 3, (BSpec.big_endian? ? 'l<' : 'l>'), opts
  ZScan::BSpec._append self, 10
end

#int64(opts = nil) ⇒ Object Also known as: int64_le


51
52
53
54
# File 'lib/zscan/bspec.rb', line 51

def int64 opts=nil
  _append_expect 4, (BSpec.big_endian? ? 'q>' : 'q<'), opts
  ZScan::BSpec._append self, 11
end

#int64_swap(opts = nil) ⇒ Object Also known as: int64_be


56
57
58
59
# File 'lib/zscan/bspec.rb', line 56

def int64_swap opts=nil
  _append_expect 4, (BSpec.big_endian? ? 'q<' : 'q>'), opts
  ZScan::BSpec._append self, 12
end

#int8(opts = nil) ⇒ Object


21
22
23
24
# File 'lib/zscan/bspec.rb', line 21

def int8 opts=nil
  _append_expect 1, 'c', opts
  ZScan::BSpec._append self, 5
end

#singleObject Also known as: single_le, float


93
94
95
# File 'lib/zscan/bspec.rb', line 93

def single
  ZScan::BSpec._append self, 19
end

#single_swapObject Also known as: single_be


97
98
99
# File 'lib/zscan/bspec.rb', line 97

def single_swap
  ZScan::BSpec._append self, 20
end

#uint16(opts = nil) ⇒ Object Also known as: uint16_le


61
62
63
64
# File 'lib/zscan/bspec.rb', line 61

def uint16 opts=nil
  _append_expect 2, (BSpec.big_endian? ? 'S>' : 'S<'), opts
  ZScan::BSpec._append self, 13
end

#uint16_swap(opts = nil) ⇒ Object Also known as: uint16_be


66
67
68
69
# File 'lib/zscan/bspec.rb', line 66

def uint16_swap opts=nil
  _append_expect 2, (BSpec.big_endian? ? 'S<' : 'S>'), opts
  ZScan::BSpec._append self, 14
end

#uint32(opts = nil) ⇒ Object Also known as: uint32_le


71
72
73
74
# File 'lib/zscan/bspec.rb', line 71

def uint32 opts=nil
  _append_expect 3, (BSpec.big_endian? ? 'L>' : 'L<'), opts
  ZScan::BSpec._append self, 15
end

#uint32_swap(opts = nil) ⇒ Object Also known as: uint32_be


76
77
78
79
# File 'lib/zscan/bspec.rb', line 76

def uint32_swap opts=nil
  _append_expect 3, (BSpec.big_endian? ? 'L<' : 'L>'), opts
  ZScan::BSpec._append self, 16
end

#uint64(opts = nil) ⇒ Object Also known as: uint64_le


81
82
83
84
# File 'lib/zscan/bspec.rb', line 81

def uint64 opts=nil
  _append_expect 4, (BSpec.big_endian? ? 'Q>' : 'Q<'), opts
  ZScan::BSpec._append self, 17
end

#uint64_swap(opts = nil) ⇒ Object Also known as: uint64_be


86
87
88
89
# File 'lib/zscan/bspec.rb', line 86

def uint64_swap opts=nil
  _append_expect 4, (BSpec.big_endian? ? 'Q<' : 'Q>'), opts
  ZScan::BSpec._append self, 18
end

#uint8(opts = nil) ⇒ Object Also known as: byte


26
27
28
29
# File 'lib/zscan/bspec.rb', line 26

def uint8 opts=nil
  _append_expect 1, 'C', opts
  ZScan::BSpec._append self, 6
end