Module: MessagePack::Inspect::JSONLStreamer

Defined in:
lib/msgpack/inspect/streamer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.object(io, depth, index) ⇒ Object



255
256
257
258
259
260
261
262
263
# File 'lib/msgpack/inspect/streamer.rb', line 255

def self.object(io, depth, index)
  if depth > 1 && index > 0
    io.print ","
  end
  retval = yield
  io.print "}"
  io.puts "" if depth == 1
  retval
end

.objects(io, depth) ⇒ Object



251
252
253
# File 'lib/msgpack/inspect/streamer.rb', line 251

def self.objects(io, depth)
  yield
end

Instance Method Details

#attributes(io) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/msgpack/inspect/streamer.rb', line 290

def attributes(io)
  write(:format, :header)

  super

  write(:error) if @error

  case @format
  when :fixint, :uint8, :uint16, :uint32, :uint64, :int8, :int16, :int32, :int64
    write(:data, :value)
  when :fixmap, :map16, :map32
    write(:length)
  when :fixarray, :array16, :array32
    write(:length)
  when :fixstr, :str8, :str16, :str32
    write(:length, :data, :value)
  when :nil
    write(:data, :value)
  when :false
    write(:data, :value)
  when :true
    write(:data, :value)
  when :bin8, :bin16, :bin32
    write(:length, :data, :value)
  when :ext8, :ext16, :ext32, :fixext1, :fixext2, :fixext4, :fixext8, :fixext16
    if @value
      write(:exttype, :length, :data, :value)
    else
      write(:exttype, :length, :data)
    end
  when :float32, :float64
    write(:data, :value)
  when :never_used
    write(:data)
  end
end

#element_keyObject



339
340
341
342
343
344
345
346
347
# File 'lib/msgpack/inspect/streamer.rb', line 339

def element_key
  if @first_kv_pair
    @first_kv_pair = false
  else
    @io.print ","
  end
  @io.print  %!{"key":!
  super
end

#element_valueObject



349
350
351
352
353
# File 'lib/msgpack/inspect/streamer.rb', line 349

def element_value
  @io.print  %!,"value":!
  super
  @io.print %!}!
end

#elements(&block) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
# File 'lib/msgpack/inspect/streamer.rb', line 327

def elements(&block)
  @io.print ","
  if @length == 0
    @io.print %!"children":[]!
    return
  end

  @io.print %!"children":[!
  super
  @io.print %!]!
end

#write(*attrs) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/msgpack/inspect/streamer.rb', line 265

def write(*attrs)
  attrs.each do |attr|
    @io.print "," unless @first_obj
    case attr
    when :format
      @io.print %!{"format":"#{@format.to_s}"!
    when :header
      @io.print %!"header":"0x#{hex(@header)}"!
    when :data
      @io.print %!"data":"0x#{@data}"!
    when :value
      if @value.nil?
        @io.print %!"value":null!
      else
        @io.print %!"value":#{@value.inspect}!
      end
    when :length
      @io.print %!"length":#{@length}!
    when :exttype
      @io.print %!"exttype":#{@exttype}!
    end
    @first_obj = false
  end
end