Class: Buffer

vertx/buffer~ Buffer

new Buffer(obj)

Most data in vert.x is shuffled around using buffers. A Buffer represents a sequence of zero or more bytes that can be written to or read from, and which expands automatically as necessary to accomodate any bytes written to it. You can perhaps think of a buffer as smart byte array. The methods documented for the Java Buffer objects are applicable to Javascript Buffer instances as well.
Parameters:
Name Type Argument Description
obj string | number | undefined <optional>
The paramater from which the buffer will be created. If a string is given it create a new Buffer which contains the string. If a number is given it will create a new Buffer which has the given initial size. if no parameter is defined a new empty Buffer will be created.
Source:
See:
Examples
var Buffer = require('vertx/buffer');
var buff   = new Buffer('Hello!');

Creating Buffers

var Buffer = require('vertx/buffer');

// Create a buffer from a string with UTF-8 encoding (the default)
var buff = new Buffer('Now is the winter of our discontent made glorioius summer');

// Create a buffer from a string and specify an encoding
buff = new Buffer('Too hot, too hot!', 'UTF-16');

// etc etc
// TODO: Finish these examples

Methods

appendBuffer(buf, offset, length) → {module:vertx/buffer~Buffer}

Append the contents of the provided buffer to this buffer.
Parameters:
Name Type Argument Description
buf module:vertx/buffer~Buffer a buffer
offset number <optional>
the offset in the provided buffer from which point bytes should be read. Defaults to 0.
length number <optional>
the number of bytes to read from the provided buffer. Defaults to buf.length() - offset.
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

appendByte(b) → {module:vertx/buffer~Buffer}

Append to the buffer.
Parameters:
Name Type Description
b number a valid signed 8 bit integer
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

appendBytes(b, o, l) → {module:vertx/buffer~Buffer}

Append a byte array to this Buffer.
Parameters:
Name Type Argument Description
b array an array of bytes
o number <optional>
offset in the byte array from which to start reading
l number <optional>
the number of bytes to read from the byte array
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

appendDouble(d) → {module:vertx/buffer~Buffer}

Append to the buffer.
Parameters:
Name Type Description
d number a valid signed 64 bit double
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

appendFloat(f) → {module:vertx/buffer~Buffer}

Append to the buffer.
Parameters:
Name Type Description
f number a valid signed 32 bit integer
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

appendInt(i) → {module:vertx/buffer~Buffer}

Append to the buffer.
Parameters:
Name Type Description
i number a valid signed 32 bit integer
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

appendShort(s) → {module:vertx/buffer~Buffer}

Append to the buffer.
Parameters:
Name Type Description
s number a valid signed 16 bit short
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

appendString(str, enc) → {module:vertx/buffer~Buffer}

Append to the buffer.
Parameters:
Name Type Argument Description
str string the string
enc string <optional>
the encoding to use or {undefined} if the default should be used.
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

copy() → {module:vertx/buffer~Buffer}

Create a copy of this buffer and its content.
Source:
Returns:
Type
module:vertx/buffer~Buffer

equals(other) → {boolean}

Determines if this buffer is equal to the other
Parameters:
Name Type Description
other module:vertx/buffer~Buffer the buffer to compare to this one
Source:
Returns:
true if the buffers are equal
Type
boolean

getBuffer(start, end) → {module:vertx/buffer~Buffer}

Get a {module:vertx/buffer~Buffer} for the given range from the buffer.
Parameters:
Name Type Description
start number of the range
end number of the range, exclusive
Source:
Returns:
Type
module:vertx/buffer~Buffer

getByte(pos) → {number}

Get an unsigned 8 bit integer from the buffer.
Parameters:
Name Type Description
pos number the position
Source:
Returns:
Type
number

getDouble(pos) → {number}

Get a signed 64 bit double from the buffer.
Parameters:
Name Type Description
pos number the position
Source:
Returns:
Type
number

getFloat(pos) → {number}

Get a signed 32 bit float from the buffer.
Parameters:
Name Type Description
pos number the position
Source:
Returns:
Type
number

getInt(pos) → {number}

Get a signed 32 bit integer from the buffer.
Parameters:
Name Type Description
pos number the position
Source:
Returns:
Type
number

getShort(pos) → {number}

Get a signed 16 bit short from the buffer.
Parameters:
Name Type Description
pos number the position
Source:
Returns:
Type
number

getString(start, end, enc) → {string}

Get a string for the given range from the buffer.
Parameters:
Name Type Argument Description
start number of the range
end number of the range, exclusive
enc string <optional>
An optional encoding for the returned string
Source:
Returns:
Type
string

length() → {number}

Get the length of the buffer
Source:
Returns:
The buffer length. Note this is the actual length of the data in the buffer, not an allocated length. For example,
Type
number
Example
var b = new Buffer(1024);
b.length(); // => 0
b = new Buffer("Hello world!");
b.length(); // => 12

setBuffer(position, buffer, offset, length) → {module:vertx/buffer~Buffer}

Sets the bytes from the provided buffer onto this buffer.
Parameters:
Name Type Argument Description
position number the position on which to set the buffer
buffer module:vertx/buffer~Buffer the buffer to read from
offset number <optional>
the point at which bytes should be read from the provided buffer. Defaults to 0.
length number <optional>
the number of bytes to read from the provided buffer. Defaults to buffer.length() - offset.
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

setByte(pos, b) → {module:vertx/buffer~Buffer}

Set on the buffer at the given position.
Parameters:
Name Type Description
pos number the position on which to set b
b number a valid signed 8 bit integer
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

setBytes(p, b, o, l) → {module:vertx/buffer~Buffer}

Sets a byte array on this Buffer at the given position.
Parameters:
Name Type Description
p number the position to begin writing in this buffer
b array an array of bytes
o number offset in the byte array from which to start reading
l number the number of bytes to read from the byte array
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

setDouble(pos, d) → {module:vertx/buffer~Buffer}

Set on the buffer at the given position.
Parameters:
Name Type Description
pos number the position on which to set d
d number a valid signed 64 bit double
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

setFloat(pos, f) → {module:vertx/buffer~Buffer}

Set on the buffer at the given position.
Parameters:
Name Type Description
pos number the position on which to set f
f number a valid signed 32 bit integer
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

setInt(pos, i) → {module:vertx/buffer~Buffer}

Set on the buffer at the given position.
Parameters:
Name Type Description
pos number the position on which to set i
i number a valid signed 32 bit integer
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

setShort(pos, s) → {module:vertx/buffer~Buffer}

Set on the buffer at the given position.
Parameters:
Name Type Description
pos number the position on which to set s
s number a valid signed 16 bit short
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

setString(pos, str, enc) → {module:vertx/buffer~Buffer}

Set a string in the buffer at the given position.
Parameters:
Name Type Argument Description
pos number the position on which to set str
str string the string
enc string <optional>
an optional encoding to use
Source:
Returns:
this
Type
module:vertx/buffer~Buffer

toString(encoding) → {string}

Returns this buffer as a string. The default encoding is UTF-8.
Parameters:
Name Type Argument Description
encoding string <optional>
An optional encoding
Source:
Returns:
This buffer as a string
Type
string