Class: Protobuf::Rpc::Buffer
- Inherits:
-
Object
- Object
- Protobuf::Rpc::Buffer
- Defined in:
- lib/protobuf/rpc/buffer.rb
Constant Summary collapse
- MODES =
[:read, :write]
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #flushed? ⇒ Boolean
-
#initialize(mode = :read, data = '') ⇒ Buffer
constructor
A new instance of Buffer.
- #reading? ⇒ Boolean
- #write(force_mode = true) ⇒ Object
- #writing? ⇒ Boolean
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/protobuf/rpc/buffer.rb', line 6 def data @data end |
#mode ⇒ Object
Returns the value of attribute mode.
5 6 7 |
# File 'lib/protobuf/rpc/buffer.rb', line 5 def mode @mode end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
6 7 8 |
# File 'lib/protobuf/rpc/buffer.rb', line 6 def size @size end |
Instance Method Details
#<<(data) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/protobuf/rpc/buffer.rb', line 35 def <<(data) @data << data if reading? get_data_size check_for_flush end end |
#flushed? ⇒ Boolean
51 52 53 |
# File 'lib/protobuf/rpc/buffer.rb', line 51 def flushed? @flush end |
#reading? ⇒ Boolean
43 44 45 |
# File 'lib/protobuf/rpc/buffer.rb', line 43 def reading? mode == :read end |
#write(force_mode = true) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/protobuf/rpc/buffer.rb', line 24 def write(force_mode=true) if force_mode and reading? mode = :write elsif not force_mode and reading? raise = 'You chose to write the buffer when in read mode' end @size = @data.length '%d-%s' % [@size, @data] end |
#writing? ⇒ Boolean
47 48 49 |
# File 'lib/protobuf/rpc/buffer.rb', line 47 def writing? mode == :write end |