Class: MessagePack::Buffer

Inherits:
Object
  • Object
show all
Defined in:
doclib/msgpack/buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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)

Overloads:

  • #initialize(options = {}) ⇒ Buffer

    Parameters:

    • options (Hash) (defaults to: {})
  • #initialize(io, options = {}) ⇒ Buffer

    This buffer writes written data into the IO when it is filled. This buffer reads data from the IO when it is empty.

    Parameters:

    • io (IO)
    • options (Hash) (defaults to: {})


25
26
# File 'doclib/msgpack/buffer.rb', line 25

def initialize(*args)
end

Instance Attribute Details

#ioObject (readonly)

Internal io

Returns:

  • 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.

Parameters:

Returns:



68
69
# File 'doclib/msgpack/buffer.rb', line 68

def <<(data)
end

#clearObject

Makes the buffer empty

Returns:

  • nil



33
34
# File 'doclib/msgpack/buffer.rb', line 33

def clear
end

#closeObject

Closes internal IO if its set. If internal IO is not set, it does nothing

Returns:

  • nil



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.

Returns:

  • (Boolean)


50
51
# File 'doclib/msgpack/buffer.rb', line 50

def empty?
end

#flushBuffer

Flushes data in the internal buffer to the internal IO. If internal IO is not set, it does nothing.

Returns:



169
170
# File 'doclib/msgpack/buffer.rb', line 169

def flush
end

#readString #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.

Overloads:

  • #read(n) ⇒ String

    Parameters:

    • n (Integer)

      bytes to read

  • #read(n, buffer) ⇒ String

    Parameters:

    • n (Integer)

      bytes to read

    • buffer (String)

      buffer to read into

Returns:



89
90
# File 'doclib/msgpack/buffer.rb', line 89

def read(n)
end

#read_allString #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.

Overloads:

  • #read_all(n) ⇒ String

    Parameters:

    • n (Integer)

      bytes to read

  • #read_all(n, buffer) ⇒ String

    Parameters:

    • n (Integer)

      bytes to read

    • buffer (String)

      buffer to read into

Returns:



110
111
# File 'doclib/msgpack/buffer.rb', line 110

def read_all(n, buffer=nil)
end

#sizeObject

Returns byte size of the buffer.

Returns:

  • nil



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.

Parameters:

  • n (Integer)

    byte size to skip

Returns:

  • (Integer)

    byte size actually skipped



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.

Parameters:

  • n (Integer)

    byte size to skip

Returns:



133
134
# File 'doclib/msgpack/buffer.rb', line 133

def skip_all(n)
end

#to_aArray

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.

Returns:

  • (Array)

    array of strings



153
154
# File 'doclib/msgpack/buffer.rb', line 153

def to_a
end

#to_strString

Returns all data in the buffer as a string. Destructive update to the returned string does NOT effect the buffer.

Returns:



142
143
# File 'doclib/msgpack/buffer.rb', line 142

def to_str
end

#write(data) ⇒ Integer

Appends the given data to the buffer.

Parameters:

Returns:

  • (Integer)

    byte size written



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.

Parameters:

  • io (IO)

Returns:

  • (Integer)

    byte size of written data



189
190
# File 'doclib/msgpack/buffer.rb', line 189

def write_to(io)
end