Returns the byte at the given index.
The number of bytes in the buffer
Process the Buf
1-byte at a time using the given
Buf.Processor, starting at index from
until
index until
.
Process the Buf
1-byte at a time using the given
Buf.Processor, starting at index from
until
index until
. Processing will halt if the processor
returns false
or after processing the final byte.
the starting index, inclusive. Must be non-negative.
the ending index, exclusive. Must be non-negative.
-1 if the processor processed all bytes or
the last processed index if the processor returns
false
.
Will return -1 if from
is greater than or equal to
until
or length.
Will return -1 if until
is greater than or equal to
length.
this mimics the design of Netty 4's
io.netty.buffer.ByteBuf.forEachByte
Returns a new buffer representing a slice of this buffer, delimited
by the indices from
inclusive and until
exclusive: [from, until)
.
Returns a new buffer representing a slice of this buffer, delimited
by the indices from
inclusive and until
exclusive: [from, until)
.
Out of bounds indices are truncated. Negative indices are not accepted.
Buf implementors should use the helpers Buf.checkSliceArgs, isSliceEmpty, and isSliceIdentity.
Helper to support 0-copy coercion to Buf.ByteArray.
Helper to support 0-copy coercion to Buf.ByteArray.
Write the entire contents of this Buf
into the given nio buffer.
Write the entire contents of this Buf
into the given nio buffer.
Partial writes aren't supported directly through this API; they can be
accomplished by first slicing the buffer.
This method should be preferred over Buf.ByteBuffer.extract
, Buf.ByteArray.Owned
,
etc family of functions when you want to control the destination of the data, as
opposed to letting the Buf
implementation manage the destination. For example, if
the data is destined for an IO operation, it may be preferable to provide a direct
nio ByteBuffer
to ensure the avoidance of intermediate heap-based representations.
ReadOnlyBufferException
if the provided buffer is read-only.
java.lang.IllegalArgumentException
when output
doesn't have enough
space as defined by ByteBuffer.remaining()
to hold the contents of this Buf
.
Buf implementors should use the helper checkWriteArgs.
Int) for writing to byte arrays.
Write the entire contents of this Buf
into the given array at
the given offset.
Write the entire contents of this Buf
into the given array at
the given offset. Partial writes aren't supported directly
through this API; they can be accomplished by first slicing the
buffer.
This method should be preferred over the Buf.ByteArray.extract
, Buf.ByteArray.Owned
,
etc family of functions when you want to control the destination of the data, as
opposed to letting the Buf
implementation manage the destination. For example, if you
want to manually set the first bytes of an Array[Byte]
and then efficiently copy the
contents of this Buf
to the remaining space.
IllegalArgumentException
when output
is too small to
contain all the data.
Buf implementors should use the helper checkWriteArgs.
write(ByteBuffer) for writing to nio buffers.
Helps implementations validate the arguments to write.
Helps implementations validate the arguments to write.
Compute the 32-bit FNV-1 hash code of this buf.
Compute the 32-bit FNV-1 hash code of this buf.
Concatenate this buffer with the given buffer.
Definitely requires copying.
Definitely requires copying.
Helps implementations of slice.
Helps implementations of slice.
Helps implementations of slice.
Helps implementations of slice.
Process the Buf
1-byte at a time using the given
Buf.Processor, starting at index 0
until
index length.
Process the Buf
1-byte at a time using the given
Buf.Processor, starting at index 0
until
index length. Processing will halt if the processor
returns false
or after processing the final byte.
-1 if the processor processed all bytes or
the last processed index if the processor returns
false
.
this mimics the design of Netty 4's
io.netty.buffer.ByteBuf.forEachByte
May require copying.
May require copying.
Buf represents a fixed, immutable byte buffer with efficient positional access. Buffers may be sliced and concatenated, and thus be used to implement bytestreams.
com.twitter.io.Buf.Empty for an empty
Buf
.com.twitter.io.Buf.apply for creating a
Buf
from otherBufs
com.twitter.io.Buf.ByteBuffer for an
nio.ByteBuffer
backed implementation.com.twitter.io.Buf.ByteArray for an
Array[Byte]
backed implementation.