vertx.buffer documentation
Functions for operating on Vert.x Buffers.
A Buffer represents a sequence of zero or more bytes that can be
written to or read from, and which expands as necessary to
accommodate any bytes written to it.
append!, set! and as-buffer take several different types of data
that can be written to a buffer these types are referred to
collectively as "bufferable", and are:
* Buffer
* Byte
* byte[]
* Double
* BigDecimal (coerced to a Double)
* Ratio (coerced to a Double)
* Float
* Integer
* Long
* BigInt (coerced to a Long)
* Short
* String
append!
(append! buf data)
(append! buf data-string encoding)
Appends bufferable data to the end of a buffer.
Returns the mutated buffer instance.
as-buffer
(as-buffer data)
Wraps bufferable data in a buffer unless it is already one.
buffer
(buffer)
(buffer arg)
(buffer str enc)
Creates a new Buffer instance.
arg can be:
* a String, which will be written to the buffer as UTF-8
* a byte[], which will be written to the buffer
* an int, which specifies an initial size hint
You can also provide a String along with a second argument
specifying the encoding.
delimited-parser
(delimited-parser delim handler)
Creates a delimited RecordParser.
A delimited parser can be used to parse protocol data that may be
delivered across many buffers. For example, a delimited parser
with a delimiter of "\n" would take:
buffer1:Hello\nHow are y
buffer2:ou?\nI am
buffer3:fine.
buffer4:\n
and invoke the handler three times with:
buffer1:Hello
buffer2:How are you?
buffer3:I am fine.
handler can either be a single-arity fn or a Handler instance that
will be passed the Buffer for each parsed fragment. See
org.vertx.java.core.parsetools.RecordParser for more details.
fixed-parser
(fixed-parser size handler)
Creates a fixed-size RecordParser.
A fixed-size parser can be used to parse protocol data that may be
delivered across many buffers. For example, a fixed-size parser
with a size of 4 would take:
buffer1:1234567
buffer2:8
buffer3:90123456
and invoke the handler four times with:
buffer1:1234
buffer2:5678
buffer3:9012
buffer4:3456
handler can either be a single-arity fn or a Handler instance that
will be passed the Buffer for each parsed fragment. See
org.vertx.java.core.parsetools.RecordParser for more details.
get-buffer
(get-buffer buf start end)
Returns a copy of a sub-sequence of buf as a Buffer starting
at start and ending at end - 1.
get-byte
(get-byte buf pos)
Returns the byte at position pos in buf.
Throws IndexOutOfBoundsException if the specified pos is less than 0
or pos + 1 is greater than the length of buf.
get-bytes
(get-bytes buf)
(get-bytes buf start end)
Returns a copy of all or a portion of buf as a java byte array.
If start and end are provided, it returns a copy of a sub-sequnce
starting at start and ending at end - 1, otherwise it returns a
copy of the entire buf.
get-double
(get-double buf pos)
Returns the double at position pos in buf.
Throws IndexOutOfBoundsException if the specified pos is less than 0
or pos + 8 is greater than the length of buf.
get-float
(get-float buf pos)
Returns the float at position pos in buf.
Throws IndexOutOfBoundsException if the specified pos is less than 0
or pos + 4 is greater than the length of buf.
get-int
(get-int buf pos)
Returns the int at position pos in buf.
Throws IndexOutOfBoundsException if the specified pos is less than 0
or pos + 4 is greater than the length of buf.
get-long
(get-long buf pos)
Returns the long at position pos in buf.
Throws IndexOutOfBoundsException if the specified pos is less than 0
or pos + 8 is greater than the length of buf.
get-short
(get-short buf pos)
Returns the short at position pos in buf.
Throws IndexOutOfBoundsException if the specified pos is less than 0
or pos + 2 is greater than the length of buf.
get-string
(get-string buf start end)
(get-string buf start end encoding)
Returns a copy of a sub-sequence the buf as a String starting at
start and ending at end - 1 in the given encoding (defaulting to
UTF-8).
parse-buffer
(parse-buffer parser buf)
Parses buf with parser.
parse-delimited
(parse-delimited buf delim handler)
Convience function that creates a delimited parser and uses it to parse buf.
parse-fixed
(parse-fixed buf size handler)
Convience function that creates a fixed-size parser and uses it to parse buf.
set!
(set! buf loc data)
(set! buf loc data-string encoding)
Sets bufferable data in a buffer.
The data is set at the offset specified by loc.