Class: CBOR::Unpacker

Inherits:
Object
  • Object
show all
Defined in:
lib/cbor-packed.rb

Instance Method Summary collapse

Constructor Details

#initialize(match_array, prefix_array, suffix_array) ⇒ Unpacker

Returns a new instance of Unpacker.



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/cbor-packed.rb', line 143

def initialize(match_array, prefix_array, suffix_array)
  @simple_array = match_array[0...16]
  @tagged_array = match_array[16..-1]
  # index with 2i for i >= 0 or ~2i for i < 0
  # no map as we need to populate in progress
  # pp prefix_array
  @prefix_array = []
  prefix_array.each {|x| @prefix_array << x.to_unpacked_cbor1(self)}
  @suffix_array = []
  suffix_array.each {|x| @prefix_array << x.to_unpacked_cbor1(self)}
  # XXX order? -- must do lazily!
end

Instance Method Details

#unprefix(n) ⇒ Object



165
166
167
# File 'lib/cbor-packed.rb', line 165

def unprefix(n)
  @prefix_array[n]
end

#unsimple(sv) ⇒ Object

XXX order? – must do lazily!



155
156
157
# File 'lib/cbor-packed.rb', line 155

def unsimple(sv)
  @simple_array[sv]
end

#unsuffix(n) ⇒ Object



168
169
170
# File 'lib/cbor-packed.rb', line 168

def unsuffix(n)
  @suffix_array[n]
end

#untag(i) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/cbor-packed.rb', line 158

def untag(i)
  # @tagged_array[(i << 1) ^ (i >> 63)]
  ix = (i << 1) ^ (i >> 63)
  ret = @tagged_array[ix]
  # warn "** UNTAG i=#{i} ix=#{ix} ret=#{ret}"
  ret
end