Class: PQCrypto::Seal::Binary::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/pq_crypto/seal/binary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes, offset = 0) ⇒ Reader

Returns a new instance of Reader.



16
17
18
19
# File 'lib/pq_crypto/seal/binary.rb', line 16

def initialize(bytes, offset = 0)
  @bytes = String(bytes).b
  @offset = Integer(offset)
end

Instance Attribute Details

#offsetObject (readonly)

Returns the value of attribute offset.



14
15
16
# File 'lib/pq_crypto/seal/binary.rb', line 14

def offset
  @offset
end

Instance Method Details

#bytes(length) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/pq_crypto/seal/binary.rb', line 25

def bytes(length)
  length = Integer(length)
  Binary.ensure_available!(@bytes, offset, length)
  value = @bytes.byteslice(offset, length).b
  @offset += length
  value
end

#finished?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/pq_crypto/seal/binary.rb', line 33

def finished?
  offset == @bytes.bytesize
end