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.
1255 1256 1257 1258 |
# File 'lib/ic_agent/candid.rb', line 1255 def initialize(buffer = '', length = 0) @buffer = buffer @view = buffer[0...buffer.size] end |
Instance Method Details
#buffer ⇒ Object
1260 1261 1262 |
# File 'lib/ic_agent/candid.rb', line 1260 def buffer @view end |
#end? ⇒ Boolean
1268 1269 1270 |
# File 'lib/ic_agent/candid.rb', line 1268 def end? length == 0 end |
#length ⇒ Object
1264 1265 1266 |
# File 'lib/ic_agent/candid.rb', line 1264 def length @view.size end |
#read(num) ⇒ Object
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 |
# File 'lib/ic_agent/candid.rb', line 1272 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
1283 1284 1285 1286 1287 |
# File 'lib/ic_agent/candid.rb', line 1283 def readbyte res = @view[0, 2] @view = @view[2...@view.length] return res end |