Class: Baykit::BayServer::Util::SimpleBuffer
- Inherits:
-
Object
- Object
- Baykit::BayServer::Util::SimpleBuffer
- Includes:
- Reusable
- Defined in:
- lib/baykit/bayserver/util/simple_buffer.rb
Constant Summary collapse
- INITIAL_BUFFER_SIZE =
32768
Instance Attribute Summary collapse
-
#buf ⇒ Object
readonly
Returns the value of attribute buf.
-
#capacity ⇒ Object
readonly
Returns the value of attribute capacity.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
- #bytes ⇒ Object
- #extend_buf ⇒ Object
-
#initialize(init = INITIAL_BUFFER_SIZE) ⇒ SimpleBuffer
constructor
A new instance of SimpleBuffer.
- #put(bytes, pos = 0, len = bytes.length) ⇒ Object
- #put_byte(b) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(init = INITIAL_BUFFER_SIZE) ⇒ SimpleBuffer
Returns a new instance of SimpleBuffer.
15 16 17 18 19 |
# File 'lib/baykit/bayserver/util/simple_buffer.rb', line 15 def initialize(init=INITIAL_BUFFER_SIZE) @capacity = init @buf = StringUtil.alloc(@capacity) @length = 0 end |
Instance Attribute Details
#buf ⇒ Object (readonly)
Returns the value of attribute buf.
11 12 13 |
# File 'lib/baykit/bayserver/util/simple_buffer.rb', line 11 def buf @buf end |
#capacity ⇒ Object (readonly)
Returns the value of attribute capacity.
13 14 15 |
# File 'lib/baykit/bayserver/util/simple_buffer.rb', line 13 def capacity @capacity end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
12 13 14 |
# File 'lib/baykit/bayserver/util/simple_buffer.rb', line 12 def length @length end |
Instance Method Details
#bytes ⇒ Object
21 22 23 |
# File 'lib/baykit/bayserver/util/simple_buffer.rb', line 21 def bytes() return buf end |
#extend_buf ⇒ Object
46 47 48 49 |
# File 'lib/baykit/bayserver/util/simple_buffer.rb', line 46 def extend_buf() @capacity *= 2 @buf = StringUtil.realloc(@buf, @capacity) end |
#put(bytes, pos = 0, len = bytes.length) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/baykit/bayserver/util/simple_buffer.rb', line 35 def put(bytes, pos=0, len=bytes.length) while @length + len > capacity extend_buf end len.times do |i| @buf[@length + i] = bytes[pos + i] end @length += len end |
#put_byte(b) ⇒ Object
31 32 33 |
# File 'lib/baykit/bayserver/util/simple_buffer.rb', line 31 def put_byte(b) put([b], 0, 1); end |
#reset ⇒ Object
25 26 27 28 29 |
# File 'lib/baykit/bayserver/util/simple_buffer.rb', line 25 def reset() # clear for security reason @buf.clear() @length = 0 end |