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.



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

#bufferObject



1240
1241
1242
# File 'lib/ic_agent/candid.rb', line 1240

def buffer
  @view
end

#end?Boolean

Returns:

  • (Boolean)


1248
1249
1250
# File 'lib/ic_agent/candid.rb', line 1248

def end?
  length == 0
end

#lengthObject



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

#readbyteObject



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