Alternatively, one might use a formatter to append content:
1
2
|
auto output = new TextOutput (new Array(256));
output.format ("now is the time for {} good men {}", 3, foo);
|
A slice() method returns all valid content within the array.
- invariant ¶
-
Ensure the buffer remains valid between method calls.
- this(size_t capacity, size_t growing = 0) ¶
-
capacity | The number of bytes to make available. |
growing | Chunk size of a growable instance, or zero
to prohibit expansion. |
Construct a Buffer with the specified number of bytes
and expansion policy.
- this(void[] data) ¶
-
data | The backing array to buffer within. |
Prime a buffer with an application-supplied array. All content
is considered valid for reading, and thus there is no writable
space initially available.
- this(void[] data, size_t readable) ¶
-
data | The backing array to buffer within. |
readable | The number of bytes initially made
readable. |
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.
- immutable(char)[] toString() [override, final] ¶
-
Return the name of this conduit.
- size_t read(void[] dst) [override, final] ¶
-
Transfer content into the provided dst.
dst | Destination of the content. |
Return the number of bytes read, which may be less than
dst.length. Eof is returned when no further content is
available.
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.
- size_t write(const(void)[] src) [override, final] ¶
-
Emulate OutputStream.write().
Return the number of bytes written, which may be less than
provided (conceptually). Returns Eof when the buffer becomes
full.
Appends src content to the buffer, expanding as required if
configured to do so (via the ctor).
- size_t bufferSize() [override, final, const] ¶
-
Return a preferred size for buffering conduit I/O.
- void detach() [override] ¶
-
Release external resources.
- long seek(long offset, Anchor anchor = Begin) [override] ¶
-
Seek within the constraints of assigned content.
- Array assign(void[] data) ¶
-
Reset the buffer content.
data | The backing array to buffer within. All content
is considered valid. |
The buffer instance.
Set the backing array with all content readable.
- Array assign(void[] data, size_t readable) ¶
-
data | The backing array to buffer within. |
readable | The number of bytes within data considered
valid. |
The buffer instance.
Set the backing array with some content readable. Use clear()
to reset the content (make it all writable).
- void[] assign() [final] ¶
-
Return the entire backing array.
- void[] opSlice(size_t start, size_t end) [final] ¶
-
Return a void[] read of the buffer from start to end, where
end is exclusive.
- void[] slice() [final] ¶
-
Retrieve all readable content.
A void[] read of the buffer.
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.
- void[] slice(size_t size, bool eat = true) [final] ¶
-
size | Number of bytes to access. |
eat | Whether to consume the content or not. |
The corresponding buffer slice when successful, or
null if there's not enough data available (Eof; Eob).
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.
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);
|
- Array append(const(void)[] src) [final] ¶
-
src | The content to _append. |
length | The number of bytes in src. |
A chaining reference if all content was written.
Throws an IOException indicating eof or eob if not.
Append an array to this buffer.
- bool next(scope size_t delegate(const(void)[]) scan) [final] ¶
-
scan | The delagate to invoke with the current content |
Returns true if a token was isolated, false otherwise.
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.
- size_t readable() [@property, final, const] ¶
-
Return count of _readable bytes remaining in buffer. This is
calculated simply as limit() - position().
- size_t writable() [@property, final, const] ¶
-
Return count of _writable bytes available in buffer. This is
calculated simply as capacity() - limit().
- size_t limit() [@property, final, const] ¶
-
Returns the limit of readable content within this buffer.
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.
- size_t capacity() [final, const] ¶
-
Returns the maximum capacity of this buffer.
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.
- size_t position() [final, const] ¶
-
Access buffer read position.
Returns the current read-position within this buffer
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.
- Array clear() [final] ¶
-
Reset 'position' and 'limit' to zero. This effectively
clears all content from the array.
- Array flush() [override, final] ¶
-
Emit/purge buffered content.
- size_t writer(scope size_t delegate(void[]) dg) [final] ¶
-
dg | The callback to provide buffer access to. |
Returns whatever the delegate returns.
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.
- size_t reader(scope size_t delegate(const(void)[]) dg) [final] ¶
-
Read directly from this buffer.
dg | Callback to provide buffer access to. |
Returns whatever the delegate returns.
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.