License:
BSD style: see license.txtVersion:
Mar 2004: Initial release Dec 2006: Outback releaseAuthors:
Kris
1 2 3 4 5 6 7 | // create a small buffer auto buf = new Array (256); auto foo = "to write some D"; // append some text directly to it buf.append ("now is the time for all good men ").append(foo); |
1 2 | auto output = new TextOutput (new Array(256)); output.format ("now is the time for {} good men {}", 3, foo); |
Params:
capacity | the number of bytes to make available |
growing | chunk size of a growable instance, or zero to prohibit expansion |
Remarks:
Construct a Buffer with the specified number of bytes and expansion policy.Params:
data | the backing array to buffer within |
Remarks:
Prime a buffer with an application-supplied array. All content is considered valid for reading, and thus there is no writable space initially available.Params:
data | the backing array to buffer within |
readable | the number of bytes initially made readable |
Remarks:
Prime buffer with an application-supplied array, and indicate how much readable data is already there. A write operation will begin writing immediately after the existing readable content. This is commonly used to attach a Buffer instance to a local array.Params:
dst | destination of the content |
Returns:
return the number of bytes read, which may be less than dst.length. Eof is returned when no further content is available.Remarks:
Populates the provided array with content. We try to satisfy the request from the buffer content, and read directly from an attached conduit when the buffer is empty.Params:
src | the content to write |
Returns:
return the number of bytes written, which may be less than provided (conceptually). Returns Eof when the buffer becomes full.Remarks:
Appends src content to the buffer, expanding as required if configured to do so (via the ctor).Params:
data | the backing array to buffer within. All content is considered valid |
Returns:
the buffer instanceRemarks:
Set the backing array with all content readable.Params:
data | the backing array to buffer within |
readable | the number of bytes within data considered valid |
Returns:
the buffer instanceRemarks:
Set the backing array with some content readable. Use clear() to reset the content (make it all writable).Remarks:
Return the entire backing array.Returns:
a void[] read of the bufferRemarks:
Return a void[] read of the buffer, from the current position up to the limit of valid content. The content remains in the buffer for future extraction.Params:
size | number of bytes to access |
eat | whether to consume the content or not |
Returns:
the corresponding buffer slice when successful, or null if there's not enough data available (Eof; Eob).Remarks:
Slices readable data. The specified number of bytes is readd from the buffer, and marked as having been read when the 'eat' parameter is set true. When 'eat' is set false, the read position is not adjusted. Note that the slice cannot be larger than the size of the buffer ~ use method read(void[]) instead where you simply want the content copied. Note also that the slice should be .dup'd if you wish to retain it.Examples:
1 2 3 4 5 | // create a buffer with some content auto buffer = new Buffer ("hello world"); // consume everything unread auto slice = buffer.slice (buffer.readable); |
Params:
src | the content to _append |
length | the number of bytes in src Returns a chaining reference if all content was written. Throws an IOException indicating eof or eob if not. |
Remarks:
Append an array to this bufferParams:
scan | the delagate to invoke with the current content |
Returns:
Returns true if a token was isolated, false otherwise.Remarks:
Upon success, the delegate should return the byte-based index of the consumed pattern (tail end of it). Failure to match a pattern should be indicated by returning an IConduit.Eof Note that additional iterator and/or reader instances will operate in lockstep when bound to a common buffer.Remarks:
Return count of _readable bytes remaining in buffer. This is calculated simply as limit() - position()Remarks:
Return count of _writable bytes available in buffer. This is calculated simply as capacity() - limit()Returns:
Returns the limit of readable content within this buffer.Remarks:
Each buffer has a capacity, a limit, and a position. The capacity is the maximum content a buffer can contain, limit represents the extent of valid content, and position marks the current read location.Returns:
Returns the maximum capacity of this bufferRemarks:
Each buffer has a capacity, a limit, and a position. The capacity is the maximum content a buffer can contain, limit represents the extent of valid content, and position marks the current read location.Returns:
Returns the current read-position within this bufferRemarks:
Each buffer has a capacity, a limit, and a position. The capacity is the maximum content a buffer can contain, limit represents the extent of valid content, and position marks the current read location.Remarks:
Reset 'position' and 'limit' to zero. This effectively clears all content from the array.Params:
dg | the callback to provide buffer access to |
Returns:
Returns whatever the delegate returns.Remarks:
Exposes the raw data buffer at the current _write position, The delegate is provided with a void[] representing space available within the buffer at the current _write position. The delegate should return the appropriate number of bytes if it writes valid content, or IConduit.Eof on error.Params:
dg | callback to provide buffer access to |
Returns:
Returns whatever the delegate returns.Remarks:
Exposes the raw data buffer at the current _read position. The delegate is provided with a void[] representing the available data, and should return zero to leave the current _read position intact. If the delegate consumes data, it should return the number of bytes consumed; or IConduit.Eof to indicate an error.Returns:
Available space, without any expansionRemarks:
Make some additional room in the buffer, of at least the given size. Should not be public in order to avoid issues with non-growable subclasses