Module: MPLight::Unpacker

Defined in:
lib/mplight.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



175
176
177
# File 'lib/mplight.rb', line 175

def input
  @input
end

Instance Method Details

#do_input(input) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/mplight.rb', line 183

def do_input input
  oi = @input
  init_input input
  yield
ensure
  @input = oi
end

#eof?Boolean

Returns:

  • (Boolean)


191
192
193
# File 'lib/mplight.rb', line 191

def eof?
  @input.eof?
end

#getObject



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/mplight.rb', line 195

def get
  fmt = (read 1).unpack1 "C"
  case fmt >> 7
  when 0b0 then fmt
  else
    case fmt >> 5
    when 0b111 then fmt - 256
    when 0b101 then get_str fmt&0b11111
    else
      case fmt >> 4
      when 0b1000 then get_hsh fmt&0b1111
      when 0b1001 then get_ary fmt&0b1111
      else
        case fmt
        when 0xc0 then nil
        when 0xc1 then raise ArgumentError, "Illegal format: #{fmt}"
        when 0xc2 then false
        when 0xc3 then true
        when 0xc4 then read    get_len1
        when 0xc5 then read    get_len2
        when 0xc6 then read    get_len4
        when 0xc7 then get_ext get_len1
        when 0xc8 then get_ext get_len2
        when 0xc9 then get_ext get_len4
        when 0xca then (read 4).unpack1 "g"
        when 0xcb then (read 8).unpack1 "G"
        when 0xcc then (read 1).unpack1 "C"
        when 0xcd then (read 2).unpack1 "S>"
        when 0xce then (read 4).unpack1 "L>"
        when 0xcf then (read 8).unpack1 "Q>"
        when 0xd0 then (read 1).unpack1 "c"
        when 0xd1 then (read 2).unpack1 "s>"
        when 0xd2 then (read 4).unpack1 "l>"
        when 0xd3 then (read 8).unpack1 "q>"
        when 0xd4 then get_ext  1
        when 0xd5 then get_ext  2
        when 0xd6 then get_ext  4
        when 0xd7 then get_ext  8
        when 0xd8 then get_ext 16
        when 0xd9 then get_str get_len1
        when 0xda then get_str get_len2
        when 0xdb then get_str get_len4
        when 0xdc then get_ary get_len2
        when 0xdd then get_ary get_len4
        when 0xde then get_hsh get_len2
        when 0xdf then get_hsh get_len4
        end
      end
    end
  end
end

#init_input(input) ⇒ Object



177
178
179
180
181
# File 'lib/mplight.rb', line 177

def init_input input
  @input = input
  @input.binmode
  self
end