Package core :: Module buffer :: Class Buffer

[hide private]
[frames] | no frames]

# Class Buffer

source code

    object --+
             |
            Buffer

A Buffer represents a sequence of zero or more bytes that can be written to or read from, and which expands as necessary to accomodate any bytes written to it.

Buffers are used in many places in vert.x, for example to read/write data to/from NetSocket, AsyncFile, WebSocket, HttpClientRequest, HttpClientResponse, HttpServerRequest, HttpServerResponse etc.

There are two ways to write data to a Buffer: The first method involves methods that take the form set_XXX. These methods write data into the buffer starting at the specified position. The position does not have to be inside data that has already been written to the buffer; the buffer will automatically expand to encompass the position plus any data that needs to be written. All positions are measured in bytes and start with zero.

The second method involves methods that take the form append-XXX; these methods append data at the end of the buffer. Methods exist to both set and append all primitive types, String and other instances of Buffer.

Data can be read from a buffer by invoking methods which take the form get_XXX. These methods take a parameter representing the position in the Buffer from where to read data.

Instance Methods | [hide private]

__init__(self, buffer) | source code

__repr__(self) String representation of buffer | source code

to_string(self, enc="UTF-8") Buffer in enc encoding | source code

get_byte(self, pos) Get the byte at position pos in the buffer. | source code

get_fixnum(self, pos, bytes) Get the fixnum represented by a sequence of bytes starting at position pos in the buffer. | source code

get_float(self, pos, bytes) Get the float represented by a sequence of bytes starting at position pos in the buffer. | source code

get_string(self, pos, end_pos, enc='UTF-8') Return bytes from the buffer interpreted as a String | source code

get_buffer(self, pos, end_pos) Return bytes in the buffer as a Buffer | source code

append_buffer(self, buff) Appends a buffer to the end of this buffer. | source code

append_fixnum(self, num, bytes) Appends a fixnum to the end of this buffer. | source code

append_float(self, num, bytes) Appends a float to the end of this buffer. | source code

append_str(self, str, enc="UTF-8") Appends a string to the end of this buffer. | source code

set_fixnum(self, pos, num, bytes) Sets bytes in the buffer to a representation of a fixnum. | source code

set_float(self, pos, num, bytes) Sets bytes in the buffer to a representation of a float. | source code

set_buffer(self, pos, buff) Sets bytes in this buffer to the bytes of the specified buffer. | source code

set_string(self, pos, str, enc="UTF-8") Set bytes in the buffer to the string encoding in the specified encoding | source code

length(self) The length of this buffer, in bytes. | source code

copy(self) Get a copy of the entire buffer. | source code

_to_java_buffer(self) private | source code

Static Methods | [hide private]

create_from_str(str, enc="UTF-8") Create a buffer from a string in the enc encoding | source code

create(initial_size_hint=0) Creates a new empty buffer. | source code

Method Details | [hide private]

### __init__(self, buffer)
(Constructor)

source code

Overrides: object.__init__
  (inherited documentation)

### __repr__(self)
(Representation operator)

source code

String representation of buffer

Overrides: object.__repr__

### create(initial_size_hint=0)
Static Method

source code

Creates a new empty buffer. initial_size_hint is a hint to the system for how much memory to initially allocate.

### append_buffer(self, buff)

source code

Appends a buffer to the end of this buffer. The buffer will expand as necessary to accomodate any bytes written.

### append_fixnum(self, num, bytes)

source code

Appends a fixnum to the end of this buffer. The buffer will expand as necessary to accomodate any bytes written.

### append_float(self, num, bytes)

source code

Appends a float to the end of this buffer. The buffer will expand as necessary to accomodate any bytes written.

### append_str(self, str, enc="UTF-8")

source code

Appends a string to the end of this buffer. The buffer will expand as necessary to accomodate any bytes written.

### set_fixnum(self, pos, num, bytes)

source code

Sets bytes in the buffer to a representation of a fixnum. The buffer will expand as necessary to accomodate any bytes written.

### set_float(self, pos, num, bytes)

source code

Sets bytes in the buffer to a representation of a float. The buffer will expand as necessary to accomodate any bytes written.

### set_buffer(self, pos, buff)

source code

Sets bytes in this buffer to the bytes of the specified buffer. The buffer will expand as necessary to accomodate any bytes written.

### length(self)

source code

The length of this buffer, in bytes.

Decorators:
  - `@property`