Class: MessagePack::Buffer

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Buffer) initialize(options = {}) - (Buffer) initialize(io, options = {})

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:

  • - (Buffer) initialize(options = {})

    Parameters:

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

    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

- (Object) io (readonly)

Internal io

Returns:

  • IO



161
162
163
# File 'doclib/msgpack/buffer.rb', line 161

def io
  @io
end

Instance Method Details

- (Buffer) <<(data)

Appends the given data to the buffer.

Parameters:

Returns:



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

def <<(data)
end

- (Object) clear

Makes the buffer empty

Returns:

  • nil



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

def clear
end

- (Object) close

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

- (Boolean) empty?

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

- (Buffer) flush

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

- (String) read - (String) read(n) - (String) read(n, buffer)

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:

  • - (String) read(n)

    Parameters:

    • n (Integer)

      bytes to read

  • - (String) read(n, buffer)

    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

- (String) read_all - (String) read_all(n) - (String) read_all(n, buffer)

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:

  • - (String) read_all(n)

    Parameters:

    • n (Integer)

      bytes to read

  • - (String) read_all(n, buffer)

    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

- (Object) size

Returns byte size of the buffer.

Returns:

  • nil



41
42
# File 'doclib/msgpack/buffer.rb', line 41

def size
end

- (Integer) skip(n)

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

- (Buffer) skip_all(n)

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

- (Array) to_a

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

- (String) to_str

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

- (Integer) write(data)

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

- (Integer) write_to(io)

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