Class: BinaryBlocker::FixedUTF16StringEncoder

Inherits:
SimpleEncoder show all
Defined in:
lib/blocker.rb

Instance Method Summary collapse

Methods inherited from SimpleEncoder

#inspect, register, #valid?

Methods inherited from Encoder

#block, #deblock, #key_value?, #me

Constructor Details

#initialize(*opts) ⇒ FixedUTF16StringEncoder

Returns a new instance of FixedUTF16StringEncoder.

Raises:

  • (ArgumentError)


511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/blocker.rb', line 511

def initialize(*opts)
  initialize_options(*opts)
  
  @length = @opts[:length].to_i
  @length *= 2
  raise ArgumentError.new("Missing or invalid string length") unless @length > 0
  @format = "Z#{@length}"
  
  @key = @opts[:key]
  @valid = @opts[:valid]
  
  initialize_data(*opts)
end

Instance Method Details

#internal_block(val) ⇒ Object



525
526
527
# File 'lib/blocker.rb', line 525

def internal_block(val)
  [Uconv.u8tou16(val || "")].pack(@format)
end

#internal_deblock(io) ⇒ Object



529
530
531
532
# File 'lib/blocker.rb', line 529

def internal_deblock(io)
  buffer = io.read(@length)
  Uconv.u16tou8(buffer).sub(/\000+$/,'')
end