Class: MessagePack::Buffer
- Inherits:
-
Object
- Object
- MessagePack::Buffer
- Defined in:
- doclib/msgpack/buffer.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Internal io.
Instance Method Summary collapse
-
#<<(data) ⇒ Buffer
Appends the given data to the buffer.
-
#clear ⇒ Object
Makes the buffer empty.
-
#close ⇒ Object
Closes internal IO if its set.
-
#empty? ⇒ Boolean
Returns true if the buffer is empty.
-
#flush ⇒ Buffer
Flushes data in the internal buffer to the internal IO.
-
#initialize(*args) ⇒ Buffer
constructor
Creates a MessagePack::Buffer instance.
-
#read(n) ⇒ String
Consumes n bytes from the head of the buffer and returns consumed data.
-
#read_all(n, buffer = nil) ⇒ String
Consumes n bytes from the head of the buffer and returns consumed data.
-
#size ⇒ Object
Returns byte size of the buffer.
-
#skip(n) ⇒ Integer
Consumes n bytes from the head of the buffer.
-
#skip_all(n) ⇒ Buffer
Consumes n bytes from the head of the buffer.
-
#to_a ⇒ Array
Returns content of the buffer as an array of strings.
-
#to_str ⇒ String
Returns all data in the buffer as a string.
-
#write(data) ⇒ Integer
Appends the given data to the buffer.
-
#write_to(io) ⇒ Integer
Writes all of data in the internal buffer into the given IO.
Constructor Details
#initialize(options = {}) ⇒ Buffer #initialize(io, options = {}) ⇒ Buffer
Creates a MessagePack::Buffer instance.
io must respond to readpartial(length, [,string]) or read(string) method and write(string) or append(string) method.
Supported options:
-
:io_buffer_size buffer size to read data from the internal IO. (default: 32768)
-
:read_reference_threshold the threshold size to enable zero-copy deserialize optimization. Read strings longer than this threshold will refer the original string instead of copying it. (default: 256) (supported in MRI only)
-
:write_reference_threshold the threshold size to enable zero-copy serialize optimization. The buffer refers written strings longer than this threshold instead of copying it. (default: 524288) (supported in MRI only)
25 26 |
# File 'doclib/msgpack/buffer.rb', line 25 def initialize(*args) end |
Instance Attribute Details
#io ⇒ Object (readonly)
Internal io
161 162 163 |
# File 'doclib/msgpack/buffer.rb', line 161 def io @io end |
Instance Method Details
#<<(data) ⇒ Buffer
Appends the given data to the buffer.
68 69 |
# File 'doclib/msgpack/buffer.rb', line 68 def <<(data) end |
#clear ⇒ Object
Makes the buffer empty
33 34 |
# File 'doclib/msgpack/buffer.rb', line 33 def clear end |
#close ⇒ Object
Closes internal IO if its set. If internal IO is not set, it does nothing
178 179 |
# File 'doclib/msgpack/buffer.rb', line 178 def close end |
#empty? ⇒ Boolean
Returns true if the buffer is empty. This method is slightly faster than size.
50 51 |
# File 'doclib/msgpack/buffer.rb', line 50 def empty? end |
#flush ⇒ Buffer
Flushes data in the internal buffer to the internal IO. If internal IO is not set, it does nothing.
169 170 |
# File 'doclib/msgpack/buffer.rb', line 169 def flush end |
#read ⇒ String #read(n) ⇒ String #read(n, buffer) ⇒ String
Consumes n bytes from the head of the buffer and returns consumed data. If the size of the buffer is less than n, it reads all of data in the buffer.
If n is 0, it does nothing and returns an empty string. If the optional buffer argument is given, the content of the string will be replaced with the consumed data.
89 90 |
# File 'doclib/msgpack/buffer.rb', line 89 def read(n) end |
#read_all ⇒ String #read_all(n) ⇒ String #read_all(n, buffer) ⇒ String
Consumes n bytes from the head of the buffer and returns consumed data. If the size of the buffer is less than n, it does nothing and raises EOFError.
If n is 0, it does nothing and returns an empty string. If the optional buffer argument is given, the content of the string will be replaced with the consumed data.
110 111 |
# File 'doclib/msgpack/buffer.rb', line 110 def read_all(n, buffer=nil) end |
#size ⇒ Object
Returns byte size of the buffer.
41 42 |
# File 'doclib/msgpack/buffer.rb', line 41 def size end |
#skip(n) ⇒ Integer
Consumes n bytes from the head of the buffer. If the size of the buffer is less than n, it skips all of data in the buffer and returns integer less than n.
If n is 0, it does nothing and returns 0.
122 123 |
# File 'doclib/msgpack/buffer.rb', line 122 def skip(n) end |
#skip_all(n) ⇒ Buffer
Consumes n bytes from the head of the buffer. If the size of the buffer is less than n, it does nothing and raises EOFError. If n is 0, it does nothing.
133 134 |
# File 'doclib/msgpack/buffer.rb', line 133 def skip_all(n) end |
#to_a ⇒ Array
Returns content of the buffer as an array of strings.
This method is sometimes faster than to_s because the internal structure of the buffer is a queue of buffer chunks.
153 154 |
# File 'doclib/msgpack/buffer.rb', line 153 def to_a end |
#to_str ⇒ String
Returns all data in the buffer as a string. Destructive update to the returned string does NOT effect the buffer.
142 143 |
# File 'doclib/msgpack/buffer.rb', line 142 def to_str end |
#write(data) ⇒ Integer
Appends the given data to the buffer.
59 60 |
# File 'doclib/msgpack/buffer.rb', line 59 def write(data) end |
#write_to(io) ⇒ Integer
Writes all of data in the internal buffer into the given IO. This method consumes and removes data from the internal buffer. io must respond to write(data) method.
189 190 |
# File 'doclib/msgpack/buffer.rb', line 189 def write_to(io) end |