Class: Baykit::BayServer::Util::ByteArray

Inherits:
Object
  • Object
show all
Defined in:
lib/baykit/bayserver/util/byte_array.rb

Constant Summary collapse

INITIAL_BUF_SIZE =
8192 * 4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buf = nil) ⇒ ByteArray

Returns a new instance of ByteArray.



11
12
13
14
15
16
17
# File 'lib/baykit/bayserver/util/byte_array.rb', line 11

def initialize(buf = nil)
  if(buf == nil)
    @buf = StringUtil.alloc(INITIAL_BUF_SIZE)
  else
    @buf = buf
  end
end

Instance Attribute Details

#bufObject (readonly)

Returns the value of attribute buf.



9
10
11
# File 'lib/baykit/bayserver/util/byte_array.rb', line 9

def buf
  @buf
end

Instance Method Details

#clearObject



19
20
21
# File 'lib/baykit/bayserver/util/byte_array.rb', line 19

def clear()
  @buf.clear()
end

#lengthObject



23
24
25
# File 'lib/baykit/bayserver/util/byte_array.rb', line 23

def length()
  @buf.length()
end

#put_bytes(bytes, ofs = 0, len = bytes.length) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/baykit/bayserver/util/byte_array.rb', line 27

def put_bytes(bytes, ofs = 0, len = bytes.length)
  if(bytes == nil)
    raise RuntimeError("nil bytes")
  end

  #while pos + len > @capacity
  #  extend_buf
  #end

  len.times do |i|
    if(bytes[ofs + i] == nil)
      raise RuntimeError.new("Invalid Data")
    end
    @buf.concat(bytes[ofs + i])
  end
end