Class BinaryBlocker::SimpleEncoder
In: lib/blocker.rb
Parent: Encoder
GroupEncoder ListOfEncoder Blocker FixedArrayEncoder CountedArrayEncoder Encoder SimpleEncoder BitFieldEncoder OneOfEncoder PackedNumberEncoder PackedDateEncoder PackedDateTimeEncoder FixedStringEncoder FixedUTF16StringEncoder BinaryBlocker Module: BinaryBlocker

Methods

Public Class methods

[Source]

     # File lib/blocker.rb, line 334
334:     def self.register(sym, fmt, *opts)
335:       klass = Class.new(SimpleEncoder)
336:       klass.send(:define_method,:initialize) do |*opts|
337:         initialize_options(*opts)
338:       
339:         @format = fmt
340:         @length = BinaryBlocker.sizeof_format(@format)
341:         
342:         @key = @opts[:key]
343:         @valid = @opts[:valid]
344:         
345:         initialize_data(*opts)
346:       end
347:       BinaryBlocker.register_klass(sym, klass)
348:     end

Public Instance methods

[Source]

     # File lib/blocker.rb, line 368
368:     def inspect
369:       "SE: #{self.class} - #{@format} - #{@length} - #{self.value.inspect}"
370:     end

[Source]

     # File lib/blocker.rb, line 350
350:     def internal_block(val)
351:       [val].pack(@format)
352:     end

[Source]

     # File lib/blocker.rb, line 354
354:     def internal_deblock(io)
355:       buffer = io.read(@length)
356:       result = buffer.unpack(@format)
357:       result.first
358:     end

[Source]

     # File lib/blocker.rb, line 360
360:     def valid?
361:       if @valid
362:         @valid.call(self.value)
363:       else
364:         self.value != nil && (@key == nil || @key === self.value)
365:       end
366:     end

[Validate]