Class: IcAgent::Candid::Pipe
- Inherits:
-
Object
- Object
- IcAgent::Candid::Pipe
- Defined in:
- lib/ic_agent/candid.rb
Instance Method Summary collapse
- #buffer ⇒ Object
- #end? ⇒ Boolean
-
#initialize(buffer = '', length = 0) ⇒ Pipe
constructor
A new instance of Pipe.
- #length ⇒ Object
- #read(num) ⇒ Object
- #readbyte ⇒ Object
Constructor Details
#initialize(buffer = '', length = 0) ⇒ Pipe
Returns a new instance of Pipe.
1235 1236 1237 1238 |
# File 'lib/ic_agent/candid.rb', line 1235 def initialize(buffer = '', length = 0) @buffer = buffer @view = buffer[0...buffer.size] end |
Instance Method Details
#buffer ⇒ Object
1240 1241 1242 |
# File 'lib/ic_agent/candid.rb', line 1240 def buffer @view end |
#end? ⇒ Boolean
1248 1249 1250 |
# File 'lib/ic_agent/candid.rb', line 1248 def end? length == 0 end |
#length ⇒ Object
1244 1245 1246 |
# File 'lib/ic_agent/candid.rb', line 1244 def length @view.size end |
#read(num) ⇒ Object
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 |
# File 'lib/ic_agent/candid.rb', line 1252 def read(num) if @view.size < num raise ValueError, 'Wrong: out of bound' end read_num = num * 2 res = @view[0...read_num] @view = @view[read_num...@view.length] return res end |
#readbyte ⇒ Object
1263 1264 1265 1266 1267 |
# File 'lib/ic_agent/candid.rb', line 1263 def readbyte res = @view[0, 2] @view = @view[2...@view.length] return res end |