TTransport.borrow

Attempts to return a slice of <code>len</code> bytes of incoming data, possibly copied into buf, not consuming them (i.e.: a later read will return the same data).

This method is meant to support protocols that need to read variable- length fields. They can attempt to borrow the maximum amount of data that they will need, then <code>consume()</code> what they actually use. Some transports will not support this method and others will fail occasionally, so protocols must be prepared to fall back to <code>read()</code> if borrow fails.

The transport must be open when calling this.

interface TTransport
const(ubyte)[]
borrow
(
ubyte* buf
,
size_t len
)
out (result) { version (none) assert (result is null || result.length >= len, "Buffer returned by borrow() too short."); }

Parameters

buf ubyte*

A buffer where the data can be stored if needed, or null to indicate that the caller is not supplying storage, but would like a slice of an internal buffer, if available.

len size_t

The number of bytes to borrow.

Return Value

Type: const(ubyte)[]

If the borrow succeeds, a slice containing the borrowed data, null otherwise. The slice will be at least as long as requested, but may be longer if the returned slice points into an internal buffer rather than buf.

Throws

TTransportException if an error occurs.

Meta