Class: Baykit::BayServer::Util::ByteArray
- Inherits:
-
Object
- Object
- Baykit::BayServer::Util::ByteArray
- Defined in:
- lib/baykit/bayserver/util/byte_array.rb
Constant Summary collapse
- INITIAL_BUF_SIZE =
8192 * 4
Instance Attribute Summary collapse
-
#buf ⇒ Object
readonly
Returns the value of attribute buf.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(buf = nil) ⇒ ByteArray
constructor
A new instance of ByteArray.
- #length ⇒ Object
- #put_bytes(bytes, ofs = 0, len = bytes.length) ⇒ Object
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
#buf ⇒ Object (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
#clear ⇒ Object
19 20 21 |
# File 'lib/baykit/bayserver/util/byte_array.rb', line 19 def clear() @buf.clear() end |
#length ⇒ Object
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 |