Class: Secure::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/appswarm/secure_marshal.rb

Overview

This is an interal class to keep track of data parsing, so that not too much data is copied from here to there.

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Data

Returns a new instance of Data.



15
16
17
18
# File 'lib/appswarm/secure_marshal.rb', line 15

def initialize(data)
  @data=data
  @pos=0
end

Instance Method Details

#read(len) ⇒ Object



19
20
21
22
23
24
# File 'lib/appswarm/secure_marshal.rb', line 19

def read(len)
  raise Secure::Marshal::OutOfData.new(@data) if @data.length<@pos+len
  cur=@data[@pos...(@pos+len)]
  @pos+=cur.length
  cur
end

#strObject



35
36
37
# File 'lib/appswarm/secure_marshal.rb', line 35

def str
  @data[@pos..-1]
end

#til(str) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/appswarm/secure_marshal.rb', line 25

def til(str)
  tmp=@data[(@pos..-1)]
  i=tmp.index(str)
  if i.nil?
    raise Secure::Marshal::OutOfData.new(@data)
  end
  cur=tmp[0...i]
  @pos+=cur.length+str.length
  cur
end