Class: IcAgent::Candid::Pipe

Inherits:
Object
  • Object
show all
Defined in:
lib/ic_agent/candid.rb

Instance Method Summary collapse

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

#bufferObject



1260
1261
1262
# File 'lib/ic_agent/candid.rb', line 1260

def buffer
  @view
end

#end?Boolean

Returns:

  • (Boolean)


1268
1269
1270
# File 'lib/ic_agent/candid.rb', line 1268

def end?
  length == 0
end

#lengthObject



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

#readbyteObject



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