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.
506 507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'lib/blocker.rb', line 506 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
520 521 522 523 |
# File 'lib/blocker.rb', line 520 def internal_block(val) #[Uconv.u8tou16(val || "")].pack(@format) [val.encode("UTF-16LE") || ""].pack(@format) end |
#internal_deblock(io) ⇒ Object
525 526 527 528 529 |
# File 'lib/blocker.rb', line 525 def internal_deblock(io) buffer = io.read(@length) buffer.force_encoding("UTF-16LE") buffer.encode("UTF-8").sub(/\u0000*$/,"") end |