Class: BinaryBlocker::FixedUTF16StringEncoder
- Inherits:
-
SimpleEncoder
- Object
- Encoder
- SimpleEncoder
- BinaryBlocker::FixedUTF16StringEncoder
- Defined in:
- lib/blocker.rb
Instance Method Summary collapse
-
#initialize(*opts) ⇒ FixedUTF16StringEncoder
constructor
A new instance of FixedUTF16StringEncoder.
- #internal_block(val) ⇒ Object
- #internal_deblock(io) ⇒ Object
Methods inherited from SimpleEncoder
Methods inherited from Encoder
#block, #deblock, #key_value?, #me
Constructor Details
#initialize(*opts) ⇒ FixedUTF16StringEncoder
Returns a new instance of FixedUTF16StringEncoder.
511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/blocker.rb', line 511 def initialize(*opts) (*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 |